Detect target phone number on incoming call is it for SIM 1 or for SIM 2?

一曲冷凌霜 提交于 2019-12-03 09:57:34

问题


I have an Android phone with 2 SIM card and I want to detect the target of the incoming call — is it for SIM 1 or for SIM 2. Is it possible to get the target number from call info?


回答1:


Finally I got the solution using this code. Hope it should helpful for everyone who wants to handle Dual SIM phones. Its working fine for me.

Please add below codes in your BroadcastReceiver class:

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
    }
    }
}



回答2:


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 

}

}

}



回答3:


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

this will give incoming number, whatever set is dual sim or single.



来源:https://stackoverflow.com/questions/21397028/detect-target-phone-number-on-incoming-call-is-it-for-sim-1-or-for-sim-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!