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

Notification Icon with the new Firebase Cloud Messaging system
Android location updates on background: cannot stop GPS when user terminates the app
Floating view on android marshmallow
Existing Android App Integration to Firebase
Textureview turns blank/black after I set the media player to null
Rendering problems: The following classes could not be found
Android Firebase stores custom object members with alphabet keys (e.g. “a”, “b”, “c”) only when installed via a release apk
Implementing NavigationView and ListInteractionFragmentListener
ANR using google-services:3.0.0 and firebase
Monthly leaderboard for android game
Link button with selected radio button in list view
sqlite tables in apps with data before installation in android [duplicate]
onPause() getting detected on Samsung devices because of Proximity
android - doInBackground return always false
Missing api_key/current key with Google Services 3.0.0 and Maps API key in build.gradle
how make bottomsheet in fragment not transparent

Categories

HOME
grok
graphics
dojo
pearson-correlation
banner
elasticsearch-5
extjs4.2
augeas
gson
activecollab
endpoint
do-while
job-scheduling
git-extensions
shortest-path
replication
string-concatenation
easeljs
pchart
mongoid6
exploit
fable-f#
paperjs
alm
magento-1.8
corenlp-server
jbutton
r-grid
jett
baidu-map
protege4
apiary.io
recurrent-neural-network
signals-slots
doc
android-softkeyboard
parser-generator
avcapturedevice
clang++
strftime
snapchat
jide
jboss-4.2.x
xbmc
automapper-5
gitlist
page-replacement
video-conferencing
context-sensitive-grammar
subnet
lsyncd
trigger.io
donations
materialized-path-pattern
docpad
winusb
tooleap
cifilter
avspeechsynthesizer
cassia
stream-processing
project-organization
gcloud-ruby
libav
toast
vigenere
cwrsync
snoop
fail2ban
rrule
bcache
boost-program-options
mdichild
draw2d-js
cfcache
multitasking
gwt-openlayers
gd-graph
cmmi
process-explorer
poker
wimax
panda3d
multiplexing
koken
fitbounds
wiimote
google-maps-mobile
pylucene
drupal-fivestar
aspmenu
tabpanel
qtabbar
dojo-dnd
localizable.strings
fdf
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