I just got an EVO and it chews through the battery fairly quick. I downloaded JuiceDefender to manage my mobile data connection. That seems have worked out fairly well. However, the settings are just very restricted (even on the paid versions).

As of right now I am trying to develop a much more customizable battery saving application. The main thing I am trying to do first be able to enable/disable the mobile data connection at will.

The problem is I can't find any code snippets or articles on how to do this. The only thing I have found is the following. I don't know how accurate this is, but this was all I could piece together browsing developer.android.com

If anyone can point me to anything that could help, it would be most appreciated.

UPDATE

It appears that the HTC Evo on Sprint does not use APN settings. I tested this by downloading APNDroid and watching it not work. I then made a quick app to dump all APN entries to the screen. That yielded one result and it was for mms.

Looking at the phone info when JuiceDefender is running, I found that the GSRP network is getting turned on and off. This leaves me to believe it is possible to do it through code even though every page I find asking about this same issue says it cannot be done. The kicker is they all say to do it like APNDroid. Please someone give me some insight.

The above solution from phaniKumar also requires <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/> declared in AndroidManifest.xml. Without the permission, you'll get a InvocationTargetException error thrown.
–
ChuongPhamJun 7 '13 at 23:33

2

i tried the above code..its giving me java.lang.SecurityException: Neither user 10126 nor current process has android.permission.MODIFY_PHONE_STATE... When i include <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/> in manifest. i am getting "Permission is only granted to system apps"..error..is there no other way that i can access this feature. ?
–
JohnJul 11 '14 at 11:43

I think there are two primary types of mobile data connection on an android device: WiFi and 3G/HSDPA/etc.

And afaik you should be able to disable WiFi programmatically, but I think the 3G/HSDPA/etc connections can only be disabled by changing the APN's name. The reason I'm saying this is because the popular application APNDroid does it that way.

Switching the mobile data net connectivity by changing the APN's name doesn't work well any more since Gingerbread.
And while the reflection code is probably the right way to do the trick, it won't work, because the application needs the android.permission.MODIFY_PHONE_STATE permission as explained by Alex P. Otherwise you get this nasty exception: