如何在双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
}
}
}