Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable/disable 3G/2G in Android SDK

Tags:

android

3g

I am just wondering how to enable/disable 3G/2G using the Android SDK and not just intenting to the 3G settings page. Thanks. Also is there a way to do the same thing, but with GPS. Thanks!

like image 366
Ryan Ciehanski Avatar asked May 29 '11 21:05

Ryan Ciehanski


1 Answers

There is no exported to the SDK functionality to switch between 2G and 3G. For a given device you could probably figure out the private functionality, but it wouldn't work unless the app was signed with the system key.

You can disable the radios though, by turning on airplane mode.

And you might be able to make a shortcut to open the appropriate settings activity directly, instead of going through a few levels of menus to get there.

If you make your own build, you can presumably add the capability you really want, but that's likely not useful to anyone but yourself.

Edit: further detail - to understand how it works, look at the settings menu code (default version, a given device will differ):

http://android.git.kernel.org/?p=platform/packages/apps/Phone.git;a=blob;f=src/com/android/phone/Settings.java;hb=HEAD

Edit: AOSP is no longer served from kernel.org. A browsable mirror of the current phone repository is at https://github.com/android/platform_packages_apps_phone however due to evolution of code organization there is no longer a Settings.java there. One might either use git to reconstruct the version above from this repository, or else try to figure out where the code has migrated to in current releases.

You would need to find out the implementation specific set of NT_MODE_ constants you wish to toggle between. And you need to be able to write to secure settings, which requires being signed with the system key. Unless it's a custom build, you probably don't have access to that.

like image 111
Chris Stratton Avatar answered Sep 28 '22 07:09

Chris Stratton