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

Swipe image views left and right like a drag and drop
android show multi point on esri map
Why can I not check SharedPreferences reference object is null?
Open the downloaded image from Gallery app android
How set imageview scaletype to topCrop
Value error of type java.lang.String cannot be converted to JSONArray
I got past "aidl missing' in android studios and now have 7 new errors
WebView problems in Kitkat device
Adding button makes camera preview not display
Delete Database and ListView in Android
Make the selected item bigger gridview android
Android in app billing v3 response not including orderId
How to create a Circle ListView on Android?
Android maintain variable values in Service when app is swiped away
Fragment did not create a view Exception after Orientation change
Refresh any UI when connection is back [closed]

Categories

HOME
phantom-dsl
azure-stream-analytics
google-cloud-platform
checkstyle
forms
webdriver
ns-3
shiro
seo
aws-cli
square
maxscript
jetty
google-cloud-datalab
missing-data
mvc5
azure-container-service
octave
mod-security
openbugs
endpoint
comsol
flatpak
altera
screen-readers
microsoft-dynamics-nav
google-content-api
identity-management
shortest-path
apache2.4
google-maps-autocomplete
microsoft-ocr
guzzle
php-mysqlidb
dynamically-generated
dapper-extensions
android-sharedpreferences
ms-access-web-app
fractions
intersystems-cache
rpgle
cognos-bi
sql-server-2000
git-squash
activexobject
modalviewcontroller
dm-script
android-augmented-reality
z-notation
ogc
pom.xml
vugen
scalding
reshape
mach-o
java-websocket
lsyncd
cpu-cache
cvxpy
preprocessor
adafruit
uicolor
rspec2
avspeechsynthesizer
deep
np-spring
jnlua
spring-retry
tfs-workitem
vigenere
binomial-theorem
sapscript
liquid-layout
umlgraph
broadband
apache-spark-1.3
infosphere-spl
structuremap3
cocos3d
machine-instruction
human-computer-interface
cancellation
ios8-extension
dot42
spring-remoting
dsym
cfcache
openargs
mbunit
ebay-lms
bjyauthorize
extreme-programming
zope.interface
cuda-gdb
subproject
azman
failing-tests
jsr286
google-maps-mobile
jquery-tools
winmain
jqote
clrstoredprocedure
resharper-6.0
cfwindow
django-piston
sun
product-management
appliance

Resources

Encrypt Message