I asked this question but I received no answer.
I used the following code to turn on the mobile data (3G).
private static void setMobileDataEnabled(Context context, boolean enabled){
try{
ConnectivityManager conman = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
Method setMobileDataEnabledMethod = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(conman, enabled);
}catch(NoSuchMethodException e){e.printStackTrace();}
catch(InvocationTargetException e){e.printStackTrace();}
catch(IllegalAccessException e){e.printStackTrace();}
}
I call it as:
setMobileDataEnabled(getBaseContext(), true/false);
It enable/disable the mobile data correctly, but this code doesn't work correctly on Dual SIM devices. I tested it on Motorola Razr D1, D3, in a Samsung Dual-SIM (can't remember now) but this code does not work. Everything works fine, the application doesn't crash.
Instead of "getBaseContext()", I tried "getApplicationContext()" and "this", but nothing changed.
I learned that Android wasn't designed for Dual-Chip devices, this can be a problem since I can't target any SIM card, so I'm not able to find any trick or anything else to "fix" the code, am I right ?
What I can do to switch the mobile data on/off on Dual-Chip devices? I took a look on the Source codes, the setMobileDataEnabled is "public", whe shouldn't have access to it?
I also find IConnectivityManager class, but it is not a java extention, I think it is .aidl or something (can't remember), it can be usefull?
I don't know what to do, please I do need help.
Sorry for my English.
Thanks.