I asked this question, but received no answer.
I used the following code to enable 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 like:
setMobileDataEnabled(getBaseContext(), true/false);
This correctly enables / disables mobile data, but this code does not work correctly on devices with two SIM cards. I tested it on Motorola Razr D1, D3, in Samsung Dual-SIM (I donβt remember now), but this code does not work. Everything works fine, the application does not crash.
Instead of getBaseContext (), I tried getApplicationContext () and this, but nothing changed.
I found out that Android is not intended for Dual-Chip devices, this can be a problem, because I canβt target any SIM card, so I canβt find any trick or anything else to βfixβ the code , I'm right?
What can I do to enable or disable mobile data on Dual-Chip devices? I took a look at the Source Code, setMobileDataEnabled is "publicly available", whe shouldn't have access to it?
I also find the IConnectivityManager class, but it is not a Java extension, I think it is .aidl or something (I do not remember), can this be useful?
I do not know what to do, please, I need help.
Sorry for my English.
Thanks.