2

I have a problem identifying the data roaming setting in Android L. In previous versions of Android, I was able to access either Settings.Secure or Settings.Global (depending on the Android version), and get the setting.

But now, on Android L, this no longer works. Whether data roaming is on or off, the return from the Settings.Global is always 0.

Android L supports multi SIM out of the box, so, a new manager was created to handle this: SubscriptionManager. This subscription manager, handles the several settings of the several SIM cards in the form of SubInfoRecord classes. I can retrieve the settings per SIM card.

However, the dataRoaming filed inside that class is always 0 as well.

Does anyone know how can this be achieved on the new API?

My app is a system app that comes embedded in the phones from factory so, I should be able to access all the APIs available.

However, I've spent a long time looking in the source code but I found nothing. In the Settings.Global class there's no indication that that setting no longer works on Android.

Does anyone have a clue on where this setting was moved to?

Thanks in advance!

pedrop
  • 134
  • 1
  • 7

2 Answers2

1

Check this DevicePolicyManager.setGlobalSetting as from documentation this can only be called by device owner app. Is your app is installed as device owner ? If not you can check the following links

Do something like this

    DevicePolicyManager manager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    manager.setGlobalSetting(<Admin_Component>, Settings.Global.DATA_ROAMING, <value>);

Admin_Component: Component instance

Value: "0" for disable or "1" for enable

Community
  • 1
  • 1
Akhil
  • 829
  • 1
  • 11
  • 26
  • Thanks for the answer. But I'm not trying to write. I want to read the setting. That API, allows me to set a global setting but, because of the multi sim support out of the box that Android 5 has, I don't think that would work either. From now on, I need to say for which SIM I want to activate the setting for (if it's one that concerns SIM cards). But I will look into that class source to see if I get any indication from where to go! Thanks! – pedrop Nov 21 '14 at 16:44
0

Since android 5.0, android supports multiple SIM cards, use the following code to check for data roaming.

 public static boolean isDataRoamingEnabled(Context context) {
    SubscriptionManager subMngr = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    int id = SubscriptionManager.getDefaultDataSubscriptionId();
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        return false;
    }
    SubscriptionInfo ino = subMngr.getActiveSubscriptionInfo(id);
    if (ino == null)
        return false;
    return ino.getDataRoaming() == 1;

}
Muhammad Nadeem
  • 211
  • 2
  • 14