如何在双SIM卡设备中检测来自哪个SIM卡的新拨出电话? [英] How can i detect the New outgoing call From which sim in dual sim devices?

查看:160
本文介绍了如何在双SIM卡设备中检测来自哪个SIM卡的新拨出电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过此接收方检测到新的去电:

I know that i can detect new outgoing call by this receiver :

<receiver android:name=".NewOutgoingCallReceiver">
   <intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
   </intent-filter>
  </receiver> 

在OnReceive方法中,我想知道哪个sim进行此调用?

And in OnReceive method i want to know which sim making this call ?

public class NewOutgoingCallReceiver extends BroadcastReceiver
{

@Override
public void onReceive( Context context, Intent intent )
  {
     // here i want to check which sim is making that new call 
  }
}

推荐答案

您的广播接收器收到的意图应该在捆绑软件中包含一些额外的信息,其中之一就是插槽",即SIM卡插槽.

The intent received by your broadcast receiver should have some extra information in the bundle, one of which is the 'slot' - meaning the SIM slot.

您可以像上面这样在您的示例中获得此代码-适用于API 22及更高版本:

You can get this in your example above like this - this is for API 22 and above:

public class NewOutgoingCallReceiver extends BroadcastReceiver
{
  @Override
  public void onReceive( Context context, Intent intent )
    {
       //check which sim is making that new call 
       String callSlot = "";
       Bundle bundle = intent.getExtras();
       callSlot =String.valueOf(bundle.getInt("slot", -1));
       if(callSlot == "0"){
           //Call is from SIM slot0
       } else if(callSlot =="1"){
          //Call is from SIM slot 1
       }
    }
}

这篇关于如何在双SIM卡设备中检测来自哪个SIM卡的新拨出电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆