检测来电的目标电话号码是用于SIM卡1还是SIM卡2?

8

我有一款带有2个SIM卡的安卓手机,我想要检测来电的目标——它是针对SIM卡1还是SIM卡2的。是否可以从通话信息中获取目标号码?

3个回答

2

最终我使用了这段代码找到了解决方案。希望它对想要处理双卡手机的每个人都有所帮助。它对我来说运行良好。

请在您的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
    }
    }
}

@MehulJoisar,谢谢你的信息。我在XOLO设备上进行了测试,最新的双SIM卡可以正常工作。但在我的karbonn设备上无法正常工作。因此,在Android中获取来电SIM的方法并未得到充分记录。但是,我尝试使用此代码bundle.getInt("simId")时发现在某些设备上不起作用。因此,我现在正在努力寻找更好的一致解决方案。如果您有更好的解决方案,请与我们共享。谢谢! - Jebasuthan
@Jeba,谢谢,它在Android 4.2.2上运行良好。你节省了我的时间。感谢Jeba。 - user3257415
1
@Jeba 这个不起作用。你有没有其他的解决方案,可以在所有安卓双卡设备上运行? - Manish Agrawal
可以从通话记录历史中获取这些信息吗? - Naimish B. Makwana
我们只在bundle对象中获取到这些值:[{incoming_number=+919880594424, state=RINGING}]。 - Bhagya
1
@jeba 在MI 3s 6.0设备上无法工作,获取的simid = -1。 - Gundu Bandgar

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 

}

}

}

-1
Bundle bundle = intent.getExtras();
    String state = bundle.getString(TelephonyManager.EXTRA_STATE);
    if (state != null){
        callFromSecondSimNo = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
    }

这将提供传入号码,无论设置是双卡还是单卡。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接