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 correct recreate programmatically Layout
Null object Refference Error on sending data from one fragment to another [duplicate]
I don't know what happend
Google Play Developer API version_name
Double Intent for call skype/phone
AlarmsManager triggers whenever it wants
OkHttp bad requestBody
How to open the push notifications and read the text in Android/iOS device from Appium?
Fetch inbox messages from a specific number and show them in a List
Parsing Retrofit2 result using Gson with different JSON structures
How can i make effect of stack of cards using vertical RecyclerView in android
Gson fromJson parsing a list sometimes returning null
How to provide System Priviliges to Android App
Exporting the lint list to HTML in Android Studio does not replace my index.html with the lint issues
Want to List PDF files from Download Folder. Getting Error
SyncAdapter with ContactContract

Categories

HOME
cygwin
hyperlink
angular2-material
swt
jelastic
apiblueprint
edge
limit
vimdiff
appcelerator-studio
nancy
onedrive-api
do-while
atlassian-stash
powershell-v5.0
wolframalpha
google-picker
cfml
gmm
ksh
mongoid6
google-api-client
dapper-extensions
pic32
fat
mat
dotspatial
xbox
postback
dst
gojs
dynamic-jasper
imx6
latitude-longitude
sim-toolkit
imagenet
metawidget
placeholder
phpdbg
dynamic-linq
mschart
git-flow
avx
skin
sandcastle
pure-css
parfor
xcode-server
tinkerpop3
x-tag
synonym
grass
iokit
avisynth
android-launcher
branch-and-bound
pyobjc
fail2ban
bcache
dbaccess
psr-4
tweenlite
create.js
kissfft
parallel-testing
reflector
amslidemenu
android-audiorecord
away3d
route-provider
apache-abdera
curb
predicatebuilder
lr
build-environment
strtod
complex-event-processing
unmanagedresources
ifilter
movieplayer

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile