简体   繁体   中英

Roaming detection on OnePlus One/Two/Three

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! :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM