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 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);
}
Android: How to monitor WiFi signal strength
First, make sure you have <uses-permission>
for ACCESS_WIFI_STATE
in your manifest.
Second, I'm not sure about notifications for a single connection, but to get notifications of everything the radio is seeing, you can start a scan:
wifi.startScan();
Next, when I've received successful results, I used WifiManager.SCAN_RESULTS_AVAILABLE_ACTION
in the IntentFilter
.
Then, in the receiver, I use getScanResults()
from the WifiManager
object, which also contains the signal strength.
For stopping it this way, you simply call to unregisterRecever()
(so you'll want to keep it around for referencing). I haven't tested myself to see if my scanning code can be modified to just check the current connection, but I do know I got plenty of results -- Wi-Fi signals change frequently and quickly. I suppose for monitoring a single connection, you can also just filter the scan results and look for the one the device is currently connected to.
I hope this helps a little.
How to get the connection strength of Wifi access points?
According to the Android API documentation WifiManager.getConfiguredNetworks() does not fill the signal strength paramters. This data only represents the remembered access point settings, not the visible ones.
To get actually visible networks you must call WifiManager.startScan() to initiate WiFi radio scanning and WifiManager.getScanResults() after a while to get the scanning results.
Related Topics
Android Httpclient:Networkonmainthreadexception
Problem Loading Swf File in Android
Batch Scripting - If Exist ./Sdcard/File.Any Using Adb
How to Fill Recyclerview with Gridlayoutmanager from Right to Left
How to Remove Extra Padding or Margin in Material Design Button
Force a Camera to Always Open in Portrait Mode in Android
How to Import Contacts from Phonebook to Our Application
Out of Memory While Creating Bitmaps on Device
Implementing a Simple Dagger2 Sample
Achartengine - Can't Figure How to Use Dates as X Axis - the File I Save Is Empty
Sliding Navigation Drawer Not Handling Clicks on Menu Items Android
Android - Nestedscrollview Which Contains Expandablelistview Doesn't Scroll When Expanded
Transfer Data from One Activity to Another Activity Using Intents
Broadcast Receiver Not Working in Android Oreo
Can Not Set Debuggable Flag in Androidmanifest.Xml
How to Show Text in Android System Status Bar