我正在尝试建立一个multisim Android设备(运行Android 7.0+)时,是否有任何工作/启用sim卡。为此,我遵循Google关于将多个TelephonyManagers附加到默认TelephonyManager实例的文档,如:READY
返回的TelephonyManager将对所有调用使用默认订阅。若要为特定订阅调用API,请使用createForSubscriptionId(int)。例如telephonyManager =telephonyManager
在我的具体案例中,如下所示:
telephonyManager = (TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_SERVICE_STATE);
List subList = mSubManager.getActiveSubscriptionInfoList();
SubscriptionInfo firstSub = (SubscriptionInfo) subList.get(0);
mSim0TelephonyManager = telephonyManager.createForSubscriptionId(firstSub.getSubscriptionId());
mSim0TelephonyManager.listen(new Sim0PhoneStateListener(), PhoneStateListener.LISTEN_SERVICE_STATE);
int test = mSim0TelephonyManager.getSimState();
SubscriptionInfo secondSub = (SubscriptionInfo) subList.get(1);
mSim1TelephonyManager = telephonyManager.createForSubscriptionId(secondSub.getSubscriptionId());
mSim1TelephonyManager.listen(new Sim1PhoneStateListener(), PhoneStateListener.LISTEN_SERVICE_STATE);
int testw = mSim1TelephonyManager.getSimState();所以首先,我得到所有的活动订阅,这已经是一个痛苦,因为在现实中,这些不是活动订阅,因为在服务状态的订阅中,它们只是插入到SIM插槽中的SIM卡。
这意味着,即使您禁用SIM卡使用Android设置菜单,您仍将收到该SIM卡作为一个积极的订阅!
下一个问题是,即使在停用时(没有服务!)SIM卡我得到一个值5 (READY)。对我来说,这是不可理解的,SIM状态已经准备好,而整个SIM被停用。这意味着那些API调用根本不可靠.
另外,在将PhoneStateListeners添加到单独的新TelephonyManagers之后,当SIM卡通过Android菜单激活/禁用时,我不会收到对这些PhoneStateListeners实现的任何调用.
现在我想知道的是,安卓系统内部是否出现了故障,或者设备制造商的实现(在三星A5 2017双打和华为P9 Lite上进行测试)。不幸的是,模拟器不支持multi,所以我不能在以下几个方面测试普通的Android本体版本:
更新:
同时,我发现了这个主题:How to get a PhoneStateListener when using Dual SIM functionality
实际上,Google在侦听中的实现( PhoneStateListener侦听器,int事件)中似乎存在一个bug,它导致一个PhoneStateListener只被实例化为默认的SubscriptionId,而不依赖于正在构造函数中传递的参数.
发布于 2019-09-23 12:06:50
我没有试过,但可能对你有用
subids[] = SubscriptionManager.getSubscriptionId()
if (SubscriptionManager.isActiveSubscriptionId(subids[0])){
mSim0TelephonyManager = telephonyManager.createForSubscriptionId(firstSub.getSubscriptionId());
}这会起作用的
https://stackoverflow.com/questions/47475357
复制相似问题