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 should i use android pmem or ion mermory in my app?
Front facing Camera : setparameters failed Exception On Sony xperia device
i want to use 2 android themes in android manifist?
Search date using regular expression in robotium testing
system.nullreferenceexception object reference not set to an instance
Viewing database of an app stored/installed on the device in android
Run Broadcast at specific time
Arraylist display selected listview to textview
Call service method from activity
How to change programmatically the primary color in Android L
Implementing PreferenceFragment?
3G mobile data carrier shows different website
Facebook android app permission: ask for get user profile picture
send data from ArrayList<String> to String Array (Android)
How to store multiple checkbox values in android?
On button click animation must be triggered

Categories

HOME
deep-learning
amp-html
angular-formly
devise
pyqt4
frontend
webix
special-characters
project
google-chrome-app
datastage
tput
pybossa
dimensional-modeling
identity-management
delphi-xe5
replication
windows-xp
simpleitk
articulate-storyline
strongname
itunes
google-cloud-print
quantlib
twiml
jett
login-script
reverse
fiware-cygnus
alphabetical
zoomify
sessionstorage
modernizr
node-mssql
skylink
sharp-snmp
importerror
wc
berkeley-db-je
plan-9
openresty
libgphoto2
yii2-api
twilio-click-to-call
filehandle
rmongo
donations
choice
omxplayer
resourcemanager
beamer
dimension
aurora
kiosk
yajsw
ellucian-scribe
grgit
intel-c++
google-refine
telepat
fits
procedural-programming
boost-program-options
iso-prolog
jquery-slider
sphinxql
dolby-audio-api
jquery-1.9
chart-director
wcf-configuration
dajaxice
rmiregistry
adobe-media-server
fusefabric
convention
promotion-code
android-holo-everywhere
mysql-error-1205
umra
inline-formset
cdonts
ajax-polling
burndowncharts
int64
great-circle

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