gpt4 book ai didi

android - 如何知道每次通话/短信的 SimSlot 号码?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:03:49 30 4
gpt4 key购买 nike

您只在广播接收器中知道 sim 插槽编号。经过一个月的研究,我得到了一个适合我的解决方案,如下所示

首先将 android.permission.READ_PHONE_STATE 权限添加到您的 list 文件

为您的应用程序接收调用/短信事件的电话事件实现接收器

public class CallSMSReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

Bundle extras = intent.getExtras();
if (extras != null) {
Log.d("SIM_SLOT"," Slot Number "+capturedSimSlot(extras));
}
}

/*below methods captures the sim slot number from bundle */

public int capturedSimSlot(Bundle bundle){

int whichSIM =-1;
if (bundle.containsKey("subscription")) {
whichSIM = bundle.getInt("subscription");
}
if(whichSIM >=0 && whichSIM < 5){
/*In some device Subscription id is return as subscriber id*/
sim = ""+whichSIM;
}else{
if (bundle.containsKey("simId")) {
whichSIM = bundle.getInt("simId");
}else if (bundle.containsKey("com.android.phone.extra.slot")) {
whichSIM = bundle.getInt("com.android.phone.extra.slot");
}else{
String keyName = "";
for(String key : bundle.keySet()){
if(key.contains("sim"))
keyName =key;
}
if (bundle.containsKey(keyName)) {
whichSIM = bundle.getInt(keyName);
}
}
}
return whichSIM;
}
}

最佳答案

Lollipop 22+ 中的短信

public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int slot = Integer.parseInt((String) intent.getExtras().get("slot"));
if(slot == 0){
// sim1
}
if(slot == 1){
// sim2
}
}
}

在联想K3 note中测试

关于android - 如何知道每次通话/短信的 SimSlot 号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506619/

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