是否有任何方法来获得信号强度在两个sim卡上。我找了很多东西,但找不到任何解决办法。也许有什么方法在第二张sim卡上注册接收器?我正在研究Android5.0,我知道在这个版本上,Android官方不支持双sim解决方案。我只找到了这个几乎适合我的东西:Check whether the phone is dual SIM Android dual SIM signal strength
第二个链接提供了某种方式,但我不能使用它,因为方法TelephonyManager.listenGemini不可用。
有什么帮助吗?
发布于 2015-10-01 08:26:41
请注意:以下是一些Android5.0设备特有的。它在Android5.0中使用隐藏界面,在早期的和后期版本中不能工作。特别是,当API在API 22中公开时,订阅id从long更改为int (无论如何,您都应该使用官方API )。
对于HTC M8上的Android5.0,您可以尝试以下方法来获得这两种sim卡的信号强度:
重写PhoneStateListener及其受保护的内部变量long mSubId。由于受保护的变量是隐藏的,所以需要使用反射。
public class MultiSimListener extends PhoneStateListener {
private Field subIdField;
private long subId = -1;
public MultiSimListener (long subId) {
super();
try {
// Get the protected field mSubId of PhoneStateListener and set it
subIdField = this.getClass().getSuperclass().getDeclaredField("mSubId");
subscriptionField.setAccessible(true);
subscriptionField.set(this, subId);
this.subId = subId;
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
}
}
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
// Handle the event here, subId indicates the subscription id if > 0
}
}您还需要从SubscriptionManager获取活动订阅ID的列表,以实例化该类。同样,SubscriptionManager隐藏在5.0中。
final Class<?> tmClassSM = Class.forName("android.telephony.SubscriptionManager");
// Static method to return list of active subids
Method methodGetSubIdList = tmClassSM.getDeclaredMethod("getActiveSubIdList");
long[] subIdList = (long[])methodGetSubIdList.invoke(null);然后,您可以遍历subIdList来创建MultiSimListener实例。例如:
MultiSimListener listener[subIdList[i]] = new MultiSimListener(subIdList[i]);然后,您可以像往常一样为每个侦听器调用TelephonyManager.listen。
您需要将错误和Android版本/设备检查添加到代码中,因为它只在特定的设备/版本上工作。
发布于 2020-10-20 13:33:53
在Android7 (N)上,创建与特定订阅id关联的TelephonyManager应该如下所示:
TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager = telephonyManager.createForSubscriptionId( subId );在Android5.1 (L MR1 / 22) up-6 (M / 23)上,可以在PhoneStateListner构造函数中这样做:
try
{
Field f = PhoneStateListener.class.getDeclaredField("mSubId");
f.setAccessible(true);
f.set(this, id);
}
catch (Exception e) { }这两种方法都需要READ_PHONE_STATE权限。
https://stackoverflow.com/questions/31782191
复制相似问题