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

Getting headers from a response in volley
Android rendering problems, Percent layout
SoftKeyboardStateListener not working on Lollipop devices
Android keyboard lags/is slow while closing using adjustResize
Building Android library (aar) with google endpoint client library
Sending Image from recycler view to Other Activity
Play youtube videos in app android appcelerator Android SDK 23, Ti SDK 5.1.0 and above
Tracking push notifications in Android
Is there any way to define multiple style files to avoid a single huge one in Android?
How to create action bar tab on xamarin android?
onClick, onLongClick and swipe at the same time
Notification using Alarm manager not working properly for kitkat and lollipop versions
How to update OpenSSL in Android Vitamio Library [duplicate]
Android getting element from ArrayList<LatLng>()
Does asynchronous execution means that data is not getting loaded using main thread in Android?
Android Google Plus Connection Error

Categories

HOME
django
eclipse
google-cloud-platform
paraview
ggplot2
jax-rs
3d
numbers
replace
alarm
visual-studio-emulator
regular-language
jquery-ui
discrete-mathematics
minecraft-forge
enthought
watson-conversation
datastage
dynatrace
bitnami
job-scheduling
nodemcu
selinux
resourcebundle
maze
mat
android-things
bioinformatics
failover
sqlpackage
realm-mobile-platform
eviews
testbed
instantiation
reverse
yowsup
playframework-2.1
nohup
metaprogramming
ogc
xmldocument
mesosphere
dynamic-linq
wcftestclient
launchctl
tinymce-3
identification
magic-draw
context-sensitive-grammar
excel-dna
change-tracking
rocks
lrs
adafruit
watch-os-2
delta
respondcms
shopping
kango-framework
project-organization
sha512
mirror
android-broadcast
nodelist
jbake
decoupling
xmltodict
mbunit
server-administration
redis-py
monotouch.dialog
adobe-media-server
appjs
apache-whirr
wiimote
cross-database
matlab-load
dataform
mtu
diagrams
instantiationexception
opml
build-environment
data-mapping
wordprocessingml
windows-identity
xslcompiledtransform

Resources

Encrypt Message