android


how to determine your device is connected to Wi-Fi Direct or Wi-Fi hotspot via Android programming


I want to know that my Mobile device is in Wi-Fi Direct or in hotspot connection programmatically.
Thanks please help me.
Please go through this link
Check whether android wifip2p connection was successful?
It is well explained in android developer
https://developer.android.com/guide/topics/connectivity/wifip2p.html
For wifi-direct
First add permissions in manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.nsdchat"
...
<uses-permission
android:required="true"
android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission
android:required="true"
android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission
android:required="true"
android:name="android.permission.INTERNET"/>
Then in onCreate()
private final IntentFilter intentFilter = new IntentFilter();
...
public void onCreate(Bundle savedInstanceState) {
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
WifiP2pManager.Channel channel = manager.initialize(this, getMainLooper(), null);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
}
Check this link for more methods and details
For hotspot
public void getClientList() {
int macCount = 0;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null ) {
// Basic sanity check
String mac = splitted[3];
System.out.println("Mac : Outside If "+ mac );
if (mac.matches("..:..:..:..:..:..")) {
macCount++;
/* ClientList.add("Client(" + macCount + ")");
IpAddr.add(splitted[0]);
HWAddr.add(splitted[3]);
Device.add(splitted[5]);*/
System.out.println("Mac : "+ mac + " IP Address : "+splitted[0] );
System.out.println("Mac_Count " + macCount + " MAC_ADDRESS "+ mac);
Toast.makeText(
getApplicationContext(),
"Mac_Count " + macCount + " MAC_ADDRESS "
+ mac, Toast.LENGTH_SHORT).show();
}
/* for (int i = 0; i < splitted.length; i++)
System.out.println("Addressssssss "+ splitted[i]);*/
}
}
} catch(Exception e) {
}
}

Related Links

Hot Code Push doesn't work on device in Meteor
Android - Set onEditListener for all EditTexts under a parent
Google-cloud-messaging/gcm push notification not delivered to client
New line by enter key in Android Studio?
SlidingTabLayout with active tab locked to center
How To add Activity code To Fragment Android
Setting heading colors in AppCompat Theme
How can I open TomTom navigation app from my phonegap app?
notifyDataSetChanged() doesnt work for me
How to Perform Update and Delete operation in listview item row while Click the button in CursorAdapter
Gravatar are not showing up in android app
Android App is not compatible with Samsung galaxy S4 mini
Palette library changing colors while scrolling in GridView
Unable to show ProgressDialog in AsyncTask
Force close after button click to start new activity
How to save information in a button in Android?

Categories

HOME
cheerio
developer-tools
fpga
gpu
android-studio-2.2
case
jelastic
composite-primary-key
owl-carousel
limit
hpc
x264
crystal-reports-2013
retrofit2
special-characters
32bit-64bit
reactive-programming
openpyxl
heap
siddhi
why3
rtf
libc
nancy
bitnami
job-scheduling
mvc-mini-profiler
forgot-password
asp.net-mvc-viewmodel
production
selinux
sar
beta
pic32
ms-access-web-app
amazon-quicksight
progress-bar
jaws
alm
autodesk-designautomation
keras-layer
openwhisk
sendbird
installscript
numpy-broadcasting
engine.io
magento-1.9.2.4
salesforce-communities
sessionstorage
android-augmented-reality
apns-php
health-monitoring
unordered-map
apache-stanbol
smoothstate.js
vaadin-elements
lampp
spring-integration-sftp
bluez
pdf-conversion
mach-o
cd-burning
bootstrap-tags-input
reachability
gets
mapxtreme
myspace
jboss-tools
jclouds
tracker-enabled-dbcontext
kendo-upload
piracy-prevention
ascii-art
directdraw
vhosts
dynatree
google-books
android-launcher
evolus-pencil
amiga
avahi
botan
kubuntu
user-permissions
cosine-similarity
machine-instruction
imagefilter
jqmodal
cfcache
ecslidingviewcontroller
ora-06550
mvc-editor-templates
tree-balancing
redis-py
veracity
correlated-subquery
fusefabric
apache-commons-dbutils
pinch
google-ajax-api
w3c-geolocation
jqueryform
lxr
build-environment
web-application-project
dojo-dnd
wysiwym
fdf
product-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App