If you need to display WI-FI signal strength in percentage than you just have put this method getWifiStrengthPercentage in your utility class and call it whenever you need the Signal information.
public static int getWifiStrengthPercentage(Context)
{
try
{
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 10);
int percentage = (int) ((level/10.0)*100);
return percentage;
}
catch (Exception e)
{
return 0;
}
}
We need to pass context of the activity from where we are calling this method.
You will get WI-FI strength in percentage. In case if any exception found then it will return 0;
Don't forget, you should declare the permission in your manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Hope you find it helpful.... :)
0 Comment(s)