I know it is very simple for you. Here I am just tried to get WiFi name in android pie devices. I am able to get WiFi name till Nogout devices with the help of below line of code.
String ssid = wifiInfo.getSSID();
I have tried lots of answer and Android developer docs but unfortunately, I can not get a WiFi name on my mobile(Nokia 6.1 plus). I Know I am doing mistakes.
I just want a code there I can get a wifi name from my mobile to my android studio logcat.
This is related to permissions....since API level 27 you need either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission. You may also need CHANGE_WIFI_STATE for Android 9 (that's the case for wifi scan anyway as per google permisson model
then try this code
ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiInfo.getSSID();
String name = networkInfo.getExtraInfo();
String ssid = "\"" + wifiInfo.getSSID() + "\"";
}
Try to get SSID value using
WifiManager wifiManager = (WifiManager)
context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiInfo = wifiManager.getConnectionInfo();
if it returns SSID as null, then turn on the location and try the same.
Oreo 8.1+ devices require the coarse location runtime permission as well as location services to be turned on before retrieving the connected SSID.
Check this link
Related
We have a Wifi-connected device. We need to connect to the device via wifi for installation. Once connected, the application sends the request on a ip.
This works smoothly before android 9. But I'm having some problems when I do with android 9. Because when i connect to device i getting error message like this: wi-fi has no internet acces. And requests continue on mobile data. So app can't talk with device.
Can i doing something about this problem?
I guess this is related to permissions since API level 27 you need either
android.permission.ACCESS_FINE_LOCATION
or
android.permission.ACCESS_COARSE_LOCATION
permission.
You need to CHANGE_WIFI_STATE for Android Pie.
Try this
ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiInfo.getSSID();
String name = networkInfo.getExtraInfo();
String ssid = "\"" + wifiInfo.getSSID() + "\"";
}
You can study about these changes in detail.
Refer Here
Suppose say an android phones hotspot is switched on,can an application running on the phone get access to the MAC addresses of the different devices that are trying to connect to it?
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
Also, add below permission in your manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
reference on stack overflow answer
I want to get my mac address on my android mobile, without using the Wi-fi or Bluetooth, programmatically in android.
How can I do this?
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
Dont forget to add permission for ACCESS_WIFI_STATE
I want to learn the connected wif-fi point SSID. By doing so, I will not try to connect to the same point. How can I learn SSID of that I am connected to wifi point ? Is there a method like isConnected() ?
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.d("wifiInfo", wifiInfo.toString());
Log.d("SSID",wifiInfo.getSSID());
you will need the android.permission.ACCESS_WIFI_STATE in your manifest
There is one problem:
I selected wifi "XYZ" whoz pwd was unknwn. Entered some random pwd.
It shows authentication problem. on wifi screen.
But, Log.d("SSID",wifiInfo.getSSID());
Results into "XYZ"
I want to know if somebody can tell how can I get the rate of wifi connection on my android phone?
You find the connection speed programmatically in Android as follows:
WifiManager wifiManager = Context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS
}
Note that you should use the ConnectivityManager to state your preferred network if you are anticipating use of wifi over other available networks, otherwise the speed may not actually be in use