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

why it is not a cube?
Use com.android.phone class via classloader
Android: Edit library and then update in project where i am using it
Android Datepicker Fragment - How to do something when the user sets a date?
How to obtain system time and update data from database automatically with an amount of time
Service not being killed via PendingIntent
save sqlite database android after application overwrite
Required Pull Down To Refresh and Pull Up to Load More ListView in Android
OAuth Android Response Body is incorrect
Speeding up a SQLite database android
Force onDestroy to solve memory problems
Draw a path in AndEngine to move a image or sprite
Creating custom ListView without overlapping text data
Android saving application state after a theme is applied
Intent Does Not Start in If-else
Android: How to apply LayoutParams to my RelativeLayout

Categories

HOME
spark-streaming
jmeter
ecmascript-6
ns-3
pdfbox
database-normalization
carousel
switch-statement
spring-session
modal-dialog
extjs4.2
spin
mql5
gson
mautic
xcodebuild
spring-social
selenium-ide
comsol
zerobrane
capistrano3
coin3d
mvc-mini-profiler
firefox-addon
google-data-studio
lilypond
googlebot
ksh
imagemap
object-storage
xunit
opentk
licensing
mat
nstimer
comparable
kudu
complex-numbers
utorrent
jmockit
jett
github3.py
hunspell
raft
hivemq
google-knowledge-graph
ideascript
filesystemwatcher
odroid
ods
visa
android-ibeacon
lpsolve
importerror
flask-login
monkey-testing
opencmis
ovf
builder
dtsearch
custom-font
java-bytecode-asm
opengl-4
headless
libjpeg
py2neo
objectscript
choice
dimension
observablecollection
qiime
data-protection
pushbots
exim4
piracy-prevention
decimalformat
fiware-monitoring
file-move
visual-sourcesafe-2005
baasbox
telepat
delayed-execution
sql-scripts
lnk
decoupling
menubar
notorm
cocoalibspotify-2.0
nebula
merb
android-icons
extreme-programming
veracity
subproject
promotion-code
catransform3d
listactivity
drawtobitmap
photolibrary
qglwidget
web-garden
request-headers
burndowncharts

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App