Roaming detection on OnePlus One/Two/Three

776 views Asked by At

I'm willing to detect if roaming switch on a telephone is turned off.

if (Build.VERSION.SDK_INT < 17) {
  isDataRoamingDisabled =
      (Settings.System.getInt(context.getContentResolver(), Settings.Secure.DATA_ROAMING, 0)
          == 0);
} else {
  isDataRoamingDisabled =
      (Settings.Global.getInt(context.getContentResolver(), Settings.Global.DATA_ROAMING, 0)
          == 0);
}

Unfortunately only for OnePlus One/Two/Three the setting is always false (0). On rest devices that i tested - Nexus 6P, LG G5, Samsung S5 all is working fine...

telephonyManager.isNetworkRoaming(), is not really the solution here since it detects if a user in roaming and not switch in settings.

Thanks for help! :)

1

There are 1 answers

0
Almog Baku On BEST ANSWER

I found some solution regarding this issue.. It seems like it caused by the using of Dual SIM on these devices, which adopted the newer API for this functionality. (I found it on the source code of Oxygen)

  1. This solution requires READ_PHONE_STATE permission
  2. Accessing the roaming of each subscription:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
  List<SubscriptionInfo> subscriptions = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
  for (SubscriptionInfo subscriptionInfo:subscriptions) {
    if (subscriptionInfo.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE) {
      return true;
    }
  }
  return false;
}
  1. For the rest of the devices you may use the solution you specified above.