Jignesh Ansodariya Jignesh Ansodariya - 1 year ago 73
Android Question

How to get Network Strength in Android Application?

I want to show a network strength of internet in mobile device.

now I am able to check connection from wifi or not using code below, But further I need network Signal Strength. so please tell me what code I need to add?


ConnectivityManager connectivityManager = (ConnectivityManager) context
NetworkInfo activeNetInfo = connectivityManager
NetworkInfo mobNetInfo = connectivityManager

TextView netStatus = (TextView) findViewById(R.id.netStatus);
if (activeNetInfo != null) {
netStatus.setText(" Connection Status - Connected "+activeNetInfo.getTypeName());
} else if (mobNetInfo != null) {
netStatus.setText(" Connection Status - Connected "+mobNetInfo.getTypeName());
} else {
netStatus.setText(" Connection Status - Not Connected ");

Answer Source

Try this code :

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo Info = cm.getActiveNetworkInfo();
    if (Info == null || !Info.isConnectedOrConnecting()) {
        Log.i(TAG, "No connection");
    } else {
        int netType = Info.getType();
        int netSubtype = Info.getSubtype();

        if (netType == ConnectivityManager.TYPE_WIFI) {
            Log.i(TAG, "Wifi connection");
            WifiManager wifiManager = (WifiManager) getApplication().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 

            // Need to get wifi strength
        } else if (netType == ConnectivityManager.TYPE_MOBILE) {
            Log.i(TAG, "GPRS/3G connection");
            // Need to get differentiate between 3G/GPRS
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download