The below snippet helps to find the WI-FI strength in the percentage.
public static int getWifiStrength(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 have to pass context of the activity from where we are calling this method.
It will return WI-FI strength in percentage. In case if any exception found then it will return 0;
public static int getWifiStrength(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 have to pass context of the activity from where we are calling this method.
It will return WI-FI strength in percentage. In case if any exception found then it will return 0;
No comments:
Post a Comment