-1

i want to set the system preference (by code) for just using 2g networks instead of using 3g. so far i haven't found anything that could have helped me. i suppose i need to set it via the ConnectionManager? can anyone point me in the right direction here?

xenonite
  • 1,671
  • 4
  • 28
  • 43

2 Answers2

3

Unfortunately, you can't do this. The best you can do is take the user to the relevant settings screen (Mobile Network Settings), where they can choose for themselves. There's no API to actually change the setting.

Some ROMs (e.g. CyanogenMod) build this into the system, and there may be options if you are rooted/installed as a system app, but if you want something standard/mass applicable then I'm afraid you're out of luck.

Rob Pridham
  • 4,780
  • 1
  • 26
  • 38
-1

use the following code public class CheckNetworkType extends Activity { private static final String tag = "CheckNetworkType";

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TelephonyManager tm =  (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);        
    if(tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE )
    {
        //  Network type is 2G
        Log.v(tag, "2G or GSM");
    }
    else 
    if(tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_CDMA)
    {
        // Network type is 2G
        Log.v(tag, "2G or CDMA");
    }
    else
    if(tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS)
    {
        // Network type is 3G
        Log.v(tag, "3G Network available.");
    }      
}

}

code post
  • 81
  • 5
  • 1
    and this would help me SETTING the network code in what way exactly...??? i dont want to GET the network type, i want to SET it! – xenonite Mar 30 '12 at 10:04
  • ... Quite harsh on your comment and uncalled for. What Deepak Gupta posted, can actually work for you in a application if you adapt it slightly. Deny acess to web if( tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) Back on subject, what you are asking is only possible via "hacking" or "mod rom" if you prefer. And its the ROM itself who must limit it and not the Phone settings. – Pedro Ferreira Apr 05 '12 at 14:31
  • yes it really worked for me check out the network avaliablity – code post Apr 06 '12 at 08:05