I am working with an App which contains web service things.
In that I need to know the status when the Internet speed is low. How to find the internet speed level in Android?
For example, Consider if I am using 2Mbps connection in my cell phone and when it slows to 50Kbps I need to notice that situation by making a Toast or Alert.
Thanks.
If you are connected to WiFi you can find the speed of the connection using WifiManager :
WifiInfo wifiInfo = wifiManger.getConnectionInfo();
and then from the WifiInfo you can get the current speed :
int speedMbps = wifiInfo.getLinkSpeed();
If you are on 3G, I don't think there is a standard way of finding out, maybe you can assume automatically that 3G is slow.
This is specilally to detect internet connection speed by
facebook sdk
ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
This is the code for getting speed of your internet while connected to wifi.
WifiManager wifiManager = (WifiManager)
this.getSystemService(Context.WIFI_SERVICE);
List<ScanResult> wifiList = wifiManager.getScanResults();
for (ScanResult scanResult : wifiList) {
int level = WifiManager.calculateSignalLevel(scanResult.level, 5);
String net=String.valueOf(level);
// Toast.makeText(MainActivity.this,net,Toast.LENGTH_LONG).show();
}
// Level of current connection.here rssi is the value of internet speed whose value
// can be -50,-60 and some others,you can find the speed values easily on internet.
int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
String net=String.valueOf(rssi);
Toast.makeText(MainActivity.this,net,Toast.LENGTH_LONG).show();
// -100 is the minimum speed value of your internet.
if(rssi < -100) {
slowInternet=false;
}
Related
I am developing an Android App. The app will keep trying to connect to an dedicated WiFi AP when started. This is working. However when I tested to power off the AP, so the app must have been disconnected from the AP, my app still return the SSID of the AP when I use WifiManager.getConnectionInfo().getSSID() to check the SSID, why? And how can I update the current SSID when it is not connected, even it return "unknown ssid"?
Below is the method I check the SSID, the app will invoke this method continuously:
WifiManager wifiManager; // <- In MainAativity
// ....
int checkWiFiSSID() {
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) {
Log.d(TAG, "WiFi is disabled, enable it now");
wifiManager.setWifiEnabled(true);
} else {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
// This line always show the AP SSID even the AP is powered down, why??
Log.d(TAG, "AP SSID: " + ssid);
}
}
Thank you.
UPDATE:
Having read the document carefully, I found that if the WifiManager is trying to connect to an AP, even it is not connected, the getSSID() will return its SSID. As my app is keep trying to connect to the AP once it is disconnected. I guess this is the reason, but I am not sure.
i want to send the data to server from an android app. some times i cant able to sync the whole data to server i think because of wifi db level if so what is the minimum db level can i use to start the sync. can anyone please explain me in that.
To get the db of the wifi i am using the following code
WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
List<ScanResult> scanResult = wifiManager.getScanResults();
for (int i = 0; i < scanResult.size(); i++) {
Log.d("scanResult", "Speed of wifi"+scanResult.get(i).level);//The db level of signal
}
return info.isConnected();
I have a method to detect available wifi access ppoints. My method works well but when I am not in the range I still getiing the SSID of the last scan results displayed in my xml file though I am out of the range of this SSID.
private void check_wifi_available() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (!wifi.isWifiEnabled()) {
Toast.makeText(this, "Please turn your Wi-Fi on",
Toast.LENGTH_SHORT).show();
}
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
final List<ScanResult> results = wifiManager.getScanResults();
if (results != null) {
// list of access points from the last scan
List<ScanResult> updatedResults = new ArrayList<ScanResult>();
// pick Wi-Fi access points which begins with these "SV-"
// characters.
for (int i = 0; i < results.size(); i++) {
String ssid = results.get(i).SSID;
// Pattern p = Pattern.compile("^KD-(4[0-9]{2}|500)$");
// Matcher m = p.matcher(ssid);
// if(m.matches()){}else{}
if (ssid.startsWith("KD")) {
updatedResults.add(results.get(i));
}
}
if (updatedResults.size() > 0) {
String a = deliverBestAccessPoint(updatedResults);
textWifi.setText(a.toString());
}
}
}
This is best handled by the operating system. The best you could do is set up a timer to periodically scan for WiFi devices and update the results.
Other than that, on rooted devices you may be able to manually send 802.11 requests to the access point/router and do a timeout check for replies.
To clarify: the operating system, when it is scanning for devices, sends out a broadcast message and reports what devices it hears back from. When devices are toward the edge of the 'range' they may report as being available even if connecting and maintaining a connection is problematic because the signal is not strong enough.
EDIT:
For what it's worth, ScanResult has a "level" member variable that reports the signal strength. You could do some more fine filtering for low-strength results. http://developer.android.com/reference/android/net/wifi/ScanResult.html
I am looking for a programmatic way on Android to determine whether the WIFI my device is currently connected to is "secured" using either WEP, WPA, or WPA2. I've tried Google searching and I cannot find a programmatic way to determine this. I've also looked at the TelephonyManager (http://developer.android.com/reference/android/telephony/TelephonyManager.html) which also lacks this information.
Thanks,
J
There is a way using the ScanResult object.
Something like this:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();
//get current connected SSID for comparison to ScanResult
WifiInfo wi = wifi.getConnectionInfo();
String currentSSID = wi.getSSID();
if (networkList != null) {
for (ScanResult network : networkList) {
//check if current connected SSID
if (currentSSID.equals(network.SSID)) {
//get capabilities of current connection
String capabilities = network.capabilities;
Log.d(TAG, network.SSID + " capabilities : " + capabilities);
if (capabilities.contains("WPA2")) {
//do something
} else if (capabilities.contains("WPA")) {
//do something
} else if (capabilities.contains("WEP")) {
//do something
}
}
}
}
References:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults()
http://developer.android.com/reference/android/net/wifi/ScanResult.html#capabilities
http://developer.android.com/reference/android/net/wifi/WifiInfo.html
android: Determine security type of wifi networks in range (without connecting to them)
ScanResult capabilities interpretation
I want to get the list of available routers, their SSID's and signal strengths, by doing a wifi scan.
Can you please help me out with the code?
P.S.: I am new to android. A related Example will be very much appreciated.
Below code is used to get SSID, BSSID, IP Address & RSSI...
WifiManager wifi = = (WifiManager) uMobility.getContext().getSystemService(Context.WIFI_SERVICE);
String ssid = wifi.getConnectionInfo().getSSID(); // for geting SSID
String bssid = wifi.getConnectionInfo().getBSSID(); // for geting BSSID
int ipAddress = wifi.getConnectionInfo().getIpAddress(); // for geting IP Address
int rssi = wifi.getConnectionInfo().getRssi(); // for geting RSSI