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

Retrieving sharedpreferences
UART peripherals on Android Things for Raspberry Pi 3
Difference between Bmx280 and Bmx280SensorDriver classes in Android Things bmx280 driver?
Trying to read web page's XML but getting redirected
underline one word and Bold one word in Textview XML (Android Studio)
Creating post from Android results in empty json objects
How to change Preference text appearance in Android PreferenceActivity?
Android Marshmallow - How to grant dangerous permissions to Platform Signed Application
Am I using Custom Font the right way in Xamarin Android?
Telegram source code compile error
Which e-commerce solution to use when developing an android or ios app?
How to Use API Key in Voice Application
Insert a log in LogCat that when I click on it jumps to its line in code, android?
Android BLE Connection, time interval
Get an xml element inside an element trought adapter using SoapUI
Change between multiple Layouts in AlertDialog

Categories

HOME
azure-stream-analytics
hyperlink
spark-streaming
fuelux
gpu
mstest
jsf-2.2
access
aws-cli
interpolation
google-admin-sdk
spin
github-enterprise
magnetic-cards
dynamic-sql
smartclient
connector
lilypond
libigl
angularjs-components
iis-express
playstation-portable
clickjacking
reactjs.net
carriage-return
nested-lists
latitude-longitude
metaprogramming
google-data-api
chef-solo
setup.py
branching-and-merging
escpos
dbnull
placeholder
memory-mapping
linter
datamaps
convex-optimization
corruption
aquamacs
compiler-design
css-transforms
sandcastle
cudd
pure-css
actor-platform
redbeard-ios
parfor
dotnetnuke-7
uicolor
windows-azure-queues
drawstring
lz77
nupic
halcon
httpruntime.cache
custom-errors
boomerang
r-package
dllimport
computer-architecture
wiredep
lazybones
intel-c++
phonertc
visual-sourcesafe-2005
mod-proxy
fail2ban
user-permissions
xmltype
openbabel
webmatrix-3
sip-server
device-tree
verold
fpdi
websphere-esb
multiautocompletetextview
gwt-openlayers
embedded-fonts
kendo-dataviz
code-duplication
flex++
merb
http-status-code-410
wimax
uimanageddocument
jdb
stress
virtualpathprovider
saxparseexception
entitydatasource
svk
objective-j
object-database
aspmenu
burndowncharts
unmanagedresources

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile