android - 在 Android 9(API 级别 28)上配置 APNs

标签 android device-policy-manager android-enterprise android-enterprise-features

我正在尝试使用新的 APN api

代码是这样的

DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

ComponentName deviceAdmin = new ComponentName(getApplicationContext(), DeviceAdmin.class);

ApnSetting apn = (new ApnSetting.Builder())
        .setApnTypeBitmask(ApnSetting.TYPE_DEFAULT)
        .setApnName("sonme.real.apn.url")
        .setEntryName("Some Entry")
        .setCarrierEnabled(true)
        .build();

int re = dpm.addOverrideApn(deviceAdmin, apn);

dpm.setOverrideApnsEnabled(deviceAdmin, true);

但除了 APN 菜单变得不可用(锁定为管理员 - 这没关系)之外,APN 无法正常工作

附上

我检查了 dpm.getOverrideApns(deviceAdmin); 并且添加的 apn 存在... 我还尝试设置 setProtocolsetRoamingProtocol

有什么想法吗?

最佳答案

终于明白是什么东西了

看来,当使用 API 添加 apns 时,您必须显式指定 setProtocolsetRoamingProtocolsetOperatorNumeric,这是必须的,也是必须的由 Telephony.Carriers.MCC + Telephony.Carriers.MNC 组成(在我的例子中,我必须用前导零填充 MNC)

ApnSetting apn = (new ApnSetting.Builder())
        .setApnTypeBitmask(ApnSetting.TYPE_DEFAULT)
        .setApnName("net.hotm")
        .setEntryName("HOT")
        .setCarrierEnabled(true) // enable it
        .setOperatorNumeric("425" + "07") // this is a must its consists from Telephony.Carriers.MCC + Telephony.Carriers.MNC, In my case, I had to pad the MNC with a leading zero
        .setProtocol(ApnSetting.PROTOCOL_IPV4V6) // this is a must
        .setRoamingProtocol(ApnSetting.PROTOCOL_IPV4V6) // this is a must
        .build();

int re = dpm.addOverrideApn(deviceAdmin, apn);

currApns =  dpm.getOverrideApns(deviceAdmin);

dpm.setOverrideApnsEnabled(deviceAdmin, true);

附上

MCC 和 MNC 可以从 TelephonyManager, getSimOperator() (getSimOperator().substring(3) and getSimOperator().substring(0, 3)) 获取

关于android - 在 Android 9(API 级别 28)上配置 APNs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59486140/

相关文章:

android - 如何获取仅使用 v2 方案签名的 APK 的签名校验和?

android - 无法解析 : com. android.support :appcompat-v7:15. +

android - `componentDidMount()` 导航后没有调用函数

android - 条目名称 'AndroidManifest.xml' 冲突(将 android gradle 插件更新到 3.6.0 后构建失败)

android - 更新处于 KIOSK 模式的托管 Google Play 应用

android - 是否可以在不注册 EMM 社区的情况下构建 DPC?

android - 如何将 Linphone 集成到现有的 Android 项目中

android - Android 2.2 中的设备管理应用程序

android - 如何在 Android Things 上设置设备所有者?