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

How to support ui for different medias like iphones,tablets,android phones
List Row not updated with use of Dialog
Check the fist item of my ListView
Pass data from Activity to fragment
connection from Android device to pc using socket? [duplicate]
Android stop notification in status bar while receiving message
how to display map using mapview
DatePicker dialog after reselecting datepicker shows current date
Debugging cocos 2d-x android project with ndk
R can not be resolved as a variable error when creating a new android project [duplicate]
How to save and load state of an application during change of screen orientation in android
SQLite return value incorrect
how to update listview based on edittext value in android
Soft Keyboard in android not shown when API calls
edittext focused on visible in android
What to do to ignore test case in Android?

Categories

HOME
android
algorithm
gridview
twitter-bootstrap-3
adal
cheerio
mjml
3d
seo
database-normalization
aws-cli
permissions
elasticsearch-5
sendgrid-api-v3
owin
reactive-programming
openbugs
topology
selinux
breadth-first-search
object-storage
interpreter
draft-js-plugins
data.stackexchange.com
fat
motion-detection
errbot
iis-express
sqsh
dotspatial
hibernate-validator
sammy.js
getpixel
carriage-return
arduino-ide
batching
sharepoint-workflow
swagger-php
cd
z-notation
filesystemwatcher
apns-php
health-monitoring
chef-solo
kill
plaintext
android-ibeacon
movilizer
congestion-control
flask-login
facebook-social-plugins
dapper-simplecrud
jide
servermanager
linter
fclose
scalding
ngmaterial
arules
monkey
gpg-signature
structuremap4
renaming
usart
docpad
builtins
reporting-services-2012
drawstring
jtwig
android-wake-lock
stream-processing
dbamp
fuzzywuzzy
aspen
concurrentmodification
video-player
extjs-grid
sapscript
xmltype
addressing-mode
psr-4
buffering
radiant
openargs
script#
facebook-timeline
alice
panda3d
paginator
garbage
database-create
azman
usertype
cgimage
box2d-iphone
denied
role
expression-blend-4
dataform
presentation-layer
drupal-fivestar
qtabbar
cfwindow
build-environment
tui
firefox-3
pnrp

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