Is it possible to switch APN programatically in android?

11.1k views Asked by At

I am trying to develop an app in which I need to connect to a specific APN programatically for network testing purposes.

As a user, I can do this by going to "Settings" -> "Wireless & networks" -> "Mobile Networks" (long press) -> "Access Point Names". It will even let me add a new one manually.

I want to know, is there a way an app can do that automatically? I have root permissions and everything you might need.

If anyone knows the android source, can you point me on where to look to study the behavior of this screen? I've tried to take a dive there but I'm kinda lost.

2

There are 2 answers

0
brunorey On BEST ANSWER

I'm answering my own question in addition to what was pointed by 7383. Hope this helps someone.

Similar to ApnEditor, I was actually looking for ApnSettings (link to cyanogen). I supposed this screen was provided by android and didn't suspect that "Settings" was actually an app.

The apps can't be used with an IDE as we usually do, it should be either compiled with makefiles like android or edit it's source so it's "ide-compatible" as suggested here

Now, to add or edit APNs you can't just put that code in any app. You need android.permission.WRITE_APN_SETTINGS which is a permission only available to system apps. The app won't be portable, but it appears this can be done using a rooted phone or a custom rom. More info here and here

0
siva On

I hope you are looking for this. The following links are from Android settings app source code.

add new apn

Set as default