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

Content quickly disappears
Data is not changed after editing sqlitedatabase in android
How to connect asmack (xmpp client library) with openfire (xmpp server)?
Intent Service with network state change
How to make child views automatically take a new line to fit the parent width?
Show/Hide top bar like chrome, but with some static content and a listview
Delete number from contacts
Android draw image with width 1029 * height 1029 pixel
Do I need a data connection in order to get TELEPHONY_SERVICE?
How to convert PDF to HTML on android?
cordova Android Jquery geolocation issue
Android Tests - Determine if WebView is Zoomed - Pinch Zoom
Import Facebook SDK Android Studio 0.8.14
start audio clip in background in android at a particular time
If you get invited to share a Google Play Android Developer Console then How to add the application to the console of admin which sent you a invite.?
How can I use ResultReceiver in InputMethodManager#hideSoftInputFromWindow

Categories

HOME
cygwin
jpa
paraview
prism
cheerio
ng-idle
pagination
static
apiblueprint
socket.io
pclxl
bitbucket-api
nsbundle
ado.net
spring-session
google-cloud-datalab
crystal-reports-2013
nfs
performancepoint
pcl-crypto
startup
cmdb
openbugs
frequency-distribution
qsqlquery
bitnami
azure-iot-hub
sigma.js
googlebot
gmock
google-api-client
ckfinder
beautifier
nstimer
magento-1.8
scatter3d
dumpbin
android-sugarorm
login-script
imagenet
modernizr
filesystemwatcher
resolution
smoothstate.js
fwrite
dynamic-linq
builder
convex-optimization
corruption
headless
grails-plugin
custom-lists
redbeard-ios
seek
pacemaker
preprocessor
qtplugin
qbxml
dynatree
wiredep
forwarding
rate-limiting
extjs-grid
airbrake
graphics2d
google-refine
snackbar
android-broadcast
dot42
twitter-bootstrap-rails
android-usb
cmmi
workitem
poker
dolby-audio-api
pagedown
onload-event
android-sdk-2.3
listitem
josql
jdb
mbeans
svk
object-database
easyb
isapi-extension
blender-2.49
sifr
skype4java
scrubyt
perl5.12
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