Detecting and changing programmatically data connection (GPRS/UMTS) on Android
I know that unfortunately detecting and changing programmatically data connection (GPRS/UMTS) on vanilla Android is not possible, and the common workaround is to edit APN settings. This is hardly a nice solution.
However on my device (Xperia X10) I have an additional setting near "data roaming", that allows to enable or disable MMS and data. I suppose that this is a personalization made by Sony Ericsson, and maybe even other vendors have something like 开发者_运维问答this. Is there a way to access this setting?
I don't have SE phone, but I've looked into its system dump and:
- In AOSP sources there are two internal methods in com.android.internal.telephony interface: enableDataConnectivity() and disableDataConnectivity(). This interface and its implementation is a part of the system.
- There are also two methods with same names as above in com.android.phone.PhoneInterfaceManager which is a part of Phone.apk app. These methods just call above/system ones.
- Sony modified com.android.phone.PhoneInterfaceManager.enableDataConnectivity(), so it does additional check for boolean stored in sharedPreferences. If it's false, then enableDataConnectivity() method always calls disableDataConnectivity() of com.android.internal.telephony .
- Of course this boolean is controlled through preferences screen: "MMS & data". It's stored in "com.android.phone_preferences" preferences container and pref key is: "data_service_key". Additionally when you switch this checkbox, settings activity automatically calls methods from com.android.internal.telephony to switch data state immediately.
If you want to add data connection widget or something like that to your rom, then:
- You need root.
- You need "android.uid.phone" sharedUserId to access above settings.
I think it would be best to modify Phone.apk, so it will catch special intent to enable/disable data. It would set data_service_key boolean and call one of methods from com.android.internal.telephony. This should be quite easy thing to do and then you will be able to create widgets, apps and other stuff very easily - they would use that special intent.
Have you looked at SE developer zone? I found it to be pretty useful.
精彩评论