Search code examples
androidsettings3g

Android: How to check whether 3G is enabled or not?


I need to know whether 3G connectivity is permitted on the device or not. I don't want to know what current network state is, because if you set "Network Mode" setting in "Mobile network settings" screen to "Automatic" network state could be either 2G or 3G. I just want to know which setting is selected there - 2G, 3G or Automatic (latter two mean the same for me).

Both telephonyManager.getNetworkType() and ConnectivityManage.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()

are returning current network state, which can lead me in a wrong direction, because if current state is 2G it could mean that 3G is disabled or just that 3G mode is unavailable at the specific location.


Solution

  • Updated after test on LG GT540 phone:

    You can use Settings.Secure to read preferred network mode, as in this code:

    ContentResolver cr = getContentResolver();
    int value = Secure.getInt(cr, "preferred_network_mode");
    

    On my LG GT540 with CM 7.1 firmware, I have four options:

    • GSM/WCDM (auto) - the code above returns 3
    • WCDMA only - the code above returns 2
    • GSM only - the code above returns 1
    • GMS/WCDMA (WCMDA preferred) - the code above returns 0

    Naturally, GSM is 2G and WCDMA is 3G. Note that this does not provide you with information on which connection is currently active (provided you allow both). For that, see @VikashKLumar's answer.