gpt4 book ai didi

java - 在 Multi-Sim 设备中检测来电的目标 SimCard

转载 作者:行者123 更新时间:2023-12-01 09:07:16 25 4
gpt4 key购买 nike

我已经阅读了很多帖子并尝试了许多解决方案,但所有帖子的共同点是它们都已过时,至少我找不到适用于较新版本的 Android 的解决方案。

Post 1 , 结果:intent.getExtras().getInt("simId", -1)总是返回 -1

Post 2 , 结果:intent.getExtras().getInt("slot", -1)总是返回 -1

Post 3 , 结果:

String[] array = new String[]{
"extra_asus_dial_use_dualsim",
"com.android.phone.extra.slot",
"slot",
"simslot",
"sim_slot",
"subscription",
"Subscription",
"phone",
"com.android.phone.DialingMode",
"simSlot",
"slot_id",
"simId",
"simnum",
"phone_type",
"slotId",
"slotIdx"
};

for (String item :
array) {
Log.i(TAG, "Sim Card - " + item + " -----> " + intent.getExtras().getInt(item));
}

日志:
PhoneCallReceiver: Sim Card - extra_asus_dial_use_dualsim -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.extra.slot -----> 0
PhoneCallReceiver: Sim Card - slot -----> 0
PhoneCallReceiver: Sim Card - simslot -----> 0
PhoneCallReceiver: Sim Card - sim_slot -----> 0
PhoneCallReceiver: Sim Card - subscription -----> 0
PhoneCallReceiver: Sim Card - Subscription -----> 0
PhoneCallReceiver: Sim Card - phone -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.DialingMode -----> 0
PhoneCallReceiver: Sim Card - simSlot -----> 0
PhoneCallReceiver: Sim Card - slot_id -----> 0
PhoneCallReceiver: Sim Card - simId -----> 0
PhoneCallReceiver: Sim Card - simnum -----> 0
PhoneCallReceiver: Sim Card - phone_type -----> 0
PhoneCallReceiver: Sim Card - slotId -----> 0
PhoneCallReceiver: Sim Card - slotIdx -----> 0

它为第一个 SimCard 和第二个 SimCard 显示具有相同值 0 的相同日志。

我也尝试过其他类似的帖子。没有人适用于新版本的android!

是否有另一种适用于较新版本的 Android(7.0 或更高版本)的解决方案?

最佳答案

如果你这样做了,它应该可以工作。确保您的测试设备在 Android 5.1 或更高版本上运行。在 v 5.1 中添加了双 sim 卡支持(检查 here)

public class IncomingCallInterceptor extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
String callingSIM = "";
Bundle bundle = intent.getExtras();
callingSIM = String.valueOf(bundle.getInt("simId", -1));

if(callingSIM.equals("0")){
// Incoming call from SIM1
} else if(callingSIM.equals("1")){
// Incoming call from SIM2
}
}
}

确保您在 list 中添加了以下权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

笔记 :

这些值不需要一直出现。需要网络提供商支持。请阅读文档 here

Carrier id of the current subscription. Return UNKNOWN_CARRIER_ID if the subscription is unavailable or the carrier cannot be identified.

关于java - 在 Multi-Sim 设备中检测来电的目标 SimCard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58889106/

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