且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在双SIM卡设备中检测来自哪个SIM卡的新拨出电话?

更新时间:2021-09-07 22:45:22

您的广播接收器收到的意图应该在捆绑软件中包含一些额外的信息,其中之一就是插槽",即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
       }
    }
}