我有一部带2张SIM卡的Android手机,我想检测来电的目标 - 是SIM卡还是SIM卡2.是否可以从通话信息中获取目标号码?
答案 0 :(得分:3)
最后,我使用此代码获得了解决方案。希望它对每个想要处理双卡手机的人都有帮助。它对我来说很好。
请在BroadcastReceiver类中添加以下代码:
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 == "0"){
// Incoming call from SIM1
}
else if(callingSIM =="1"){
// Incoming call from SIM2
}
}
}
答案 1 :(得分:1)
add below codes in your BroadcastReceiver class.
public class IncomingCallInterceptorReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String callingFromSIM = "";
Bundle bundle = intent.getExtras();
callingFromSIM =String.valueOf(bundle.getInt("simId", -1));
if(callingFromSIM == "0"){
// Incoming call from SIM1 Card
}
else if(callingFromSIM =="1"){
// Incoming call from SIM2 Card
}
}
}
答案 2 :(得分:-1)
Bundle bundle = intent.getExtras();
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
if (state != null){
callFromSecondSimNo = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
}
这将提供传入号码,无论设置是双卡还是单个。