There's no problem getting SSID in Android 9.0&8.0
but I can't get SSID in Android 10.0(Q).
How should I do? and Where is the document links about wifi in android 10.0? I tried to find the document but I couldn't find it.
There's no problem getting SSID in Android 9.0&8.0
WifiManager mWifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
assert mWifiManager != null;
WifiInfo info = mWifiManager.getConnectionInfo();
return info.getSSID();
ConnectivityManager connManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
assert connManager != null;
NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
if (networkInfo.isConnected()) {
if (networkInfo.getExtraInfo() != null) {
return networkInfo.getExtraInfo().replace("\"", "");
}
}
It want be get.check original post
From android 8.0 onwards we wont be getting SSID of the connected
network unless GPS is turned on.
Get SSID when WIFI is connected
WifiManager mWifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
assert mWifiManager != null;
WifiInfo info = mWifiManager.getConnectionInfo();
return info.getSSID();
Related
I want to get my own device Wi-Fi SSID and BSSID name.
How can I get this?
I tried this
WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wifiConfiguration = new WifiConfiguration();
System.out.println("BSSID"+wifiConfiguration.BSSID);
But this code gives the BSSID of the device to which i currently connected but i wants to get my own device BSSID ssid through code??
Please help Me.
If you want to get the device's hotspot SSID or BSSID, use something like this:
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Method[] methods = wifimanager.getClass().getDeclaredMethods();
for (Method m: methods) {
if (m.getName().equals("getWifiApConfiguration")) {
WifiConfiguration config = (WifiConfiguration)m.invoke(wifimanager);
String ssid = config.SSID;
String bssid = config.BSSID;
}
}
You can use WifiManager and WifiInfo for the Wifi info the device connected to, like this:
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
String ssid = info.getSSID();
String bssid = info.getBSSID();
You would need the following permissions:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Note: since Android 8.0, you would also need location permissions (ACCESS_COARSE_LOCATION) to access the SSID or BSSID because of this, also, I think you need to have the device's location settings turned on for this to work even if you have the location permissions.
Add these permissions
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
and then use this method
public static String getBSSID(Context mContext) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(mNetworkInfo.isConnected()) {
final WifiManager mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
final WifiInfo mWifiInfo = mWifiManager.getConnectionInfo();
if(mWifiInfo != null) {
return mWifiInfo.getBSSID();
}
}
return null;
}
I want to know is there any way to determine whatever I am logging should go through WIFI instead of device network,Is there any methods as part of Log entries SDK
Try this code for wifi connection or not.
private boolean checkConnectedToDesiredWifi() {
boolean connected = false;
WifiManager wifiManager =(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiManager.getConnectionInfo();
String desiredMacAddress = wifiInf.getMacAddress();
WifiInfo wifi = wifiManager.getConnectionInfo();
if (wifi != null) {
// get current router Mac address
String bssid = wifi.getBSSID();
connected = desiredMacAddress.equals(bssid);
}
return connected;
}
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 do? Thanks!
Tips:
I hope to upload my file in my app only when I connect to my home WiFi named "MyWiFi", but in other place, there are many WiFi named "MyWiFi".
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (networkInfo.isConnected()) {
// Wifi is connected
WifiManager wifiManager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
Toast.makeText(context, "OK " + ssid, Toast.LENGTH_LONG).show();
}
} else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI && ! networkInfo.isConnected()) {
Toast.makeText(context, "Wifi is disconnected: "+String.valueOf(networkInfo), Toast.LENGTH_LONG).show();
}
}
Try to use below network id.
getNetworkId()
used to identify the network when performing operations on the supplicant.
UPDATE YOUR CODE
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
int networkid = wifiInfo.getNetworkId();
Toast.makeText(context, "OK " + ssid, Toast.LENGTH_LONG).show();
Toast.makeText(context, "Network ID " + networkid, Toast.LENGTH_LONG).show();
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
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
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
Toast.makeText(this, "Name is " + ssid, Toast.LENGTH_SHORT).show();
String networkid = wifiInfo.getBSSID();
Toast.makeText(this, "Network ID " + networkid, Toast.LENGTH_SHORT).show();
I am doing a small android application, which will show established WiFi connection is automatic or Manuel. Is it possible to take WiFi access point which is set by user in default "setting" application?
Thanks, Vani
see this
[ www.developer.android.com/reference/android/net/wifi/package-summary.html]
or
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) {
WifiInfo info = wifiManager.getConnectionInfo();
if (info != null) {
String ssid = info.getSSID();
...
}
}
I need to know the wifi accesspoint name which the device is using..
How to do it?
Use the WifiManager.
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) {
WifiInfo info = wifiManager.getConnectionInfo();
if (info != null) {
String ssid = info.getSSID();
...
}
}
Then you need to add a permission to your manifest.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />