Sub Activity_Create(FirstTime As Boolean)
SetMobileDataEnabled(True)
End Sub
Sub SetMobileDataEnabled(enabled As Boolean)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
r.RunMethod2("setMobileDataEnabled", enabled, "java.lang.boolean")
End Sub
You should also add this line to the manifest editor:
my steps are :
1. compile the script
2. edit and add AddPermission(android.permission.CHANGE_NETWORK_STATE)
to androidmanifest.xml
3. copy androidmanifest.xml and test.apk to device
4. install and run it
Hello Erel
I am using an Android "panel pc" that has a 3G modem usb dongle. I can toggle the "data enabled" setting from the Android's own settings screen to reset the modem when it disconnects, but cannot get it to toggle from code. (I have tried the toggle library and the code above -- no errors, but no effect). Using the getActiveNetworkInfo() - getTypeName, I can see it registers as a network type MODEM3G and not MOBILE, which is why I think the code does not have any effect. (I can successfully toggle tethering, airplane mode and wifi, but not the data enabled.) Do you know any of any other methods that I could try or could you give me some pointers?
Ok, I address it to everybody then
I have seen that by switching Airplane mode on and off it has the same effect of redialing the data connection (using Android 4.1), but this will be a problem if I move to 4.2 as it seems they have blocked this capability going forward. I will keep looking for a long term solution.
Sub Activity_Create(FirstTime As Boolean)
SetMobileDataEnabled(True)
End Sub
Sub SetMobileDataEnabled(enabled As Boolean)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
r.RunMethod2("setMobileDataEnabled", enabled, "java.lang.boolean")
End Sub
You should also add this line to the manifest editor: