简体   繁体   English

在OnePlus一/二/三上进行漫游检测

[英]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). 不幸的是,仅对于OnePlus One / Two / Three,该设置始终为假(0)。 On rest devices that i tested - Nexus 6P, LG G5, Samsung S5 all is working fine... 在我测试过的其余设备上-Nexus 6P,LG G5,三星S5都可以正常工作...

telephonyManager.isNetworkRoaming(), is not really the solution here since it detects if a user in roaming and not switch in settings. telephonyManager.isNetworkRoaming(),在这里并不是真正的解决方案,因为它会检测用户是否在漫游中并且未切换设置。

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. 我找到了有关此问题的一些解决方案。似乎是由在这些设备上使用Dual SIM引起的,该设备为此功能采用了更新的API。 (I found it on the source code of Oxygen ) (我在Oxygen源代码上找到了它)

  1. This solution requires READ_PHONE_STATE permission 此解决方案需要READ_PHONE_STATE权限
  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. 对于其他设备,您可以使用上面指定的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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