znat
znat

Reputation: 13474

Checking if 3G is connected always returns false (even when the device is connected)

Whether or not the device has 3g/data activated. Any idea of what's happening? Thank you

My code:

public boolean isConnected3G(){
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] networks = cm.getAllNetworkInfo();
    for (NetworkInfo ni : networks) 
        if ("MOBILE".equalsIgnoreCase(ni.getTypeName())){
            Log.d(TAG,""+ni.isConnected());
            if (ni.isConnected())
                return true;
        }
    return false;       
}

Upvotes: 1

Views: 515

Answers (1)

HT03
HT03

Reputation: 320

Try to use NetworkInfo ni = cm.getActiveNetworkInfo() instead of cm.getAllNetworkInfo(); and check the network information

Upvotes: 1

Related Questions