I’m surprised I cannot find any info on the internet on this common situation: How can I start an internet connection? I looked at ConnectivityManager but it seems it is just for monitoring network connectivity.
PS: The phone will be rooted, so it is not a problem.
I found the following solution:
1) Add preferred wifi/APN(Access Point Name) configuration to phone settings
2) Enable Wifi/APN
3) Connection will be established automatically
Wifi configuration is straightforward and the following page shows how it could be done:
How to programmatically create and read WEP/EAP WiFi configurations in Android?
APN configuration is tricky. Android has some hidden API’s that allow you to access/modify these settings, and you need to use
Reflectionto do this. This might of course break with future versions of Android. The following page explains how to access/modify those settings:http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx