Reputation: 23
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.
Upvotes: 2
Views: 50019
Reputation: 1
Just dial ×#×#4636#×#× go into phone information and see down if there is GSM only your phone would not support 3G and if It's WCDMA prefferd your phone can use 3G
Upvotes: 0
Reputation: 57316
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:
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.
Upvotes: 3
Reputation: 631
you can check the 3G by using
boolean is3G3 = (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSUPA);
boolean is3G2 = (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPA);
boolean is3G = (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA);
These networks are 3G networks.
Upvotes: 1
Reputation: 1856
/**
* Checks if we have a valid Internet Connection on the device.
* @param ctx
* @return True if device has internet
*
* Code from: http://www.androidsnippets.org/snippets/131/
*/
public static boolean haveInternet(Context ctx) {
NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null || !info.isConnected()) {
return false;
}
if (info.isRoaming()) {
// here is the roaming option you can change it if you want to
// disable internet while roaming, just return false
return false;
}
return true;
}
You also need
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
in AndroidMainfest.xml
Upvotes: -1