Is there any why to get the signal status of wifi and phone's provider that is shown at the top bar? Tried to search it across Stackoverflow unsuccessfuly.
Thank in advance.
Is there any why to get the signal status of wifi and phone's provider that is shown at the top bar? Tried to search it across Stackoverflow unsuccessfuly.
Thank in advance.
To get the WiFi strength, you can create the following function:
public static int calculateSignalLevel (int Rssi, int numLevels){
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int numOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numOfLevels);
}
If you want to get the status of the device and whether it is connected to the internet, you can use the following function:
public static String getConnectivityStatusString(Context context) {
int connected = NetworkUtil.getConnectivityStatus(context);
String wifiStatus = null;
if (connected == NetworkUtil.TYPE_WIFI) {
wifiStatus = "Wifi enabled";
} else if (connected == NetworkUtil.TYPE_MOBILE) {
wifiStatus = "Mobile data enabled";
} else if (connected == NetworkUtil.TYPE_NOT_CONNECTED) {
wifiStatus = "Not connected to Internet";
}
return wifiStatus;
}
Finally, to get the name of the phone's provider, you can use the following function:
public static String carrierName(){
TelephonyManager manager =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String carrierName = manager.getNetworkOperatorName();
}
I hope this answers your question.