gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:22:00 24 4
gpt4 key购买 nike

我正在尝试使用新的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com