How To Get Unique Id Of Wifi In Android?
I can get a name of WiFi using the code String ssid = wifiInfo.getSSID(), but you know many WiFi have the same name such as 'MyWiFi', I hope to get unique id of a WiFi, how can I d
Solution 1:
Try to use below network id.
getNetworkId()
used to identify the network when performing operations on the supplicant.
UPDATE YOUR CODE
WifiManagerwifiManager= (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfowifiInfo= wifiManager.getConnectionInfo();
Stringssid= wifiInfo.getSSID();
intnetworkid= wifiInfo.getNetworkId();
Toast.makeText(context, "OK " + ssid, Toast.LENGTH_LONG).show();
Toast.makeText(context, "Network ID " + networkid, Toast.LENGTH_LONG).show();
Solution 2:
The unique id of any wifi added is NETWORK_ID[The ID number that the supplicant uses to identify this network configuration entry.].
how do i get network id?
if you have WifiConfiguration object you get get its network id
For more detial on apis look here
Solution 3:
You can use the BSSID as a unique identifier https://en.wikipedia.org/wiki/Service_set_(802.11_network)#Basic_service_set_identification_.28BSSID.29
WifiManagerwifiManager= (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiInfowifiInfo= wifiManager.getConnectionInfo();
Stringssid= wifiInfo.getSSID();
Toast.makeText(this, "Name is " + ssid, Toast.LENGTH_SHORT).show();
Stringnetworkid= wifiInfo.getBSSID();
Toast.makeText(this, "Network ID " + networkid, Toast.LENGTH_SHORT).show();
Post a Comment for "How To Get Unique Id Of Wifi In Android?"