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

Which is the fastest emulator for making an android app? [closed]
Where to report API bugs to Google? (Google Nearby Messages API)
How to check if an apk launch successfully?
What happens to a Fragment once it's removed or replaced?
Opening Default Camera using Intent , overriding other apps?
Fragment findviewbyid not working correctly
Running apktool in a bash script
ionic run android shows black and white screens before main app page
Showing a message only to new installations
Android drag and return to previous activity like Facebook and Google Photos
Gradle clean task fails for not resolving all dependencies
Dynamic Invoicing/Receipt Reporting tools for Android?
Android checkbox in listview doesn't check
Persisting array of strings with greenDao
How to manage AsyncTasks priority?
Unable to get current location of android device

Categories

HOME
uml
api
polymer
eslint
object
3d
oracle-apex-5
grafana
seo
crystal-lang
accessibility
owin
ibeacon-android
windows-ce
project-intu
libc
stellar.js
android-intent
glyphicons
template-engine
charles
comparator
gmock
nstimer
exchangewebservices
userdefaults
livelink
jmockit
jbutton
papaparse
login-script
vue-chartjs
getpixel
fossil
openproject
c9.io
stringtokenizer
sharp-snmp
plr
avcapturedevice
jboss-4.2.x
configurationmanager
manova
corruption
semantic-logging
subnet
django-1.10
materialized-path-pattern
centrifuge
myspace
mta
nikeplus-api
beamer
cifilter
kango-framework
qbxml
vhosts
canalyzer
mod-proxy
haskell-warp
jquery-forms-plugin
openbabel
apache-spark-1.3
viewer
primitive-types
teaspoon
gii
verold
websphere-esb
sbcl
http-patch
modular
printdialog
dolby-audio-api
composite-component
wp7test
monotouch.dialog
rmiregistry
multiplexing
box2d-iphone
google-maps-mobile
qglwidget
easyb
isapi-extension
localizable.strings

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