Get signal strength of WIFI and Mobile Data
Wifi:
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
In case of mobile it should work:
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();
Then You should compare this signal levels and if WIFI signal is better keep it turn on, but if mobile is better disconnect wifi
How to get signal strength android?
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> all = telephonyManager.getAllCellInfo();
CellInfoGsm cellinfogsm = (CellInfoGsm) all.get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
int strengthDbm = cellSignalStrengthGsm.getDbm();
should work fine for API 17+. I am not aware of any API to help <17, though.
How to get current cell signal strength?
There is getAllCellInfo() method in TelephonyManager added in API 17 that could be good solution. Example of use:
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
// for example value of first element
CellInfoGsm cellInfoGsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();
How to get cell service signal strength in Android?
create a PhoneStateListener and handle the onSignalStrengthChanged callback. When your app is initialized, it should give you an initial notification. This is in 1.x. in 2.x, there's an open issue about this.
How to get signal strength of connected WiFi android?
Hope it works..
public void onReceive(WifiManager wifiManager) {
int numberOfLevels=5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
Related Topics
Android - Set a Progressbar to Be a Vertical Bar Instead of Horizontal
How To: Install Plugin in Android Studio
Backup/Restore Sqlite Db in Android
Get Application Installed Date on Android
Successful Share Intent for Android
Should I Use Getapplicationcontext or Activity.This in a Long Running Asynctask
Writing Some Characters Like '<' in an Xml File
Change The Background Color of Cardview Programmatically
Add Viewpagerindicator to Android Studio
Set Visibility of Progress Bar Gone on Completion of Image Loading Using Glide Library
Android Adding a Submenu to a Menuitem, Where Is Addsubmenu()
Eclipse: Won't Let Me Use Android Sdk, Wrongly Claims My Adt Is Out of Date
Disable Webview Touch Events in Android
How to Add Background Image to Activity
What Is Better: @Suppresslint or @Targetapi