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

RecyclerView Hide behind AppbarLayout?
How to display image with intent.ACTION_VIEW
NDK Error occured while importing telegram source code from github
Picking only images from gallery Android
Getting thread error in ui automation android
E/SQLiteLog: (1) no such function: JSON_OBJECT
heroku H21 Backend connection refused
xamarin mutli selection listview
Uri to Bitmap Issue
Animated ECG using Animated Vector in Android
Spinner Value is not preserved for 2nd spinner onStart
Android - library module's interface method is not called in app module
Android MPAndroidChart line chart sorted by y-values
How to add the CheckBox value to the database?
calling another class functions from one class on button click in android
Getting information from DialogFragment using onDismiss()

Categories

HOME
kentico
adal
paraview
checkstyle
dns
amp-html
aws-cli
rom
rds
settings
crystal-reports-2013
frontend
trac
p2p
vimdiff
scrolltop
gruntfile
azure-powershell
searchview
firefox-addon
video-editing
cfml
selinux
poedit
href
highstock
direct3d11
bulletphysics
pylons
tpm
paperjs
winpe
left-join
sammy.js
vue-chartjs
amazon-ses
spring-mvc-test
apriori
ovf
mongotemplate
posixct
aquamacs
azure-cli
testrail
polyline
docpad
omxplayer
tinkerpop3
flex4.6
uicolor
signalr.client
mta
hclust
cifilter
spreadjs
libav
qt5.2
jdi
include-guards
dulwich
wso2greg
canvg
matlab-deployment
broadband
grouping-sets
packet-sniffers
formview
ss7
renderer
syndicationfeed
eclipse-kepler
mongohq
kogrid
workitem
process-explorer
mysql-error-2013
booksleeve
mkv
relative
convention
inline-formset
metaweblog
objective-j
easyb
tabpanel
dsl-tools
mathematical-notation
information-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