Android 5.0 (L) - Check data Roaming Setting

2.6k views Asked by At

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!

2

There are 2 answers

1
Akhil On

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

0
Muhammad Nadeem On

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;

}