I'm trying to work with the setMobileDataEnabled method of ConnectivityManager and for some reason i get different results on my emulator and actual device. On my device (Nexus One, running CyanogenMod 7.0) it works perfectly fine when calling this function and setting the mobile data setting correctly (after getting to this function using reflection):
ConnectivityManager connService = (ConnectivityManager) p_context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (null != connService)
{
try
{
Method setMobileDataEnabledMethod = connService.getClass().getDeclaredMethod("setMobileDataEnabled", boolean.class);
if (null != setMobileDataEnabledMethod)
{
setMobileDataEnabledMethod.invoke(connService, true);
}
}
catch (Exception ex)
{
// Error
}
}
The problem is that when I'm using the same code on the emulator I'm getting the following exception:
java.lang.reflect.InvocationTargetException
at android.net.ConnectivityManager.setMobileDataEnabled(ConnectivityManager.java:379)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
Caused by: java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
at android.os.Parcel.readException(Parcel.java:1247)
at android.os.Parcel.readException(Parcel.java:1235)
at android.net.IConnectivityManager$Stub$Proxy.setMobileDataEnabled(IConnectivityManager.java:540)
Nowhere in the documentation (that I could find...) it states that the "WRITE_SECURE_SETTINGS" permission is required for this function and I wonder if this is just an emulator issue or the fact that on my device it works is just some weird coincident ?