Skip to content Skip to sidebar Skip to footer

Detect Target Phone Number On Incoming Call Is It For Sim 1 Or For Sim 2?

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 inf

Solution 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:

publicclassIncomingCallInterceptorextendsBroadcastReceiver {
@OverridepublicvoidonReceive(Context context, Intent intent) {
    StringcallingSIM="";
    Bundlebundle= intent.getExtras();
    callingSIM =String.valueOf(bundle.getInt("simId", -1));
    if(callingSIM == "0"){
        // Incoming call from SIM1
    }
    elseif(callingSIM =="1"){
        // Incoming call from SIM2
    }
    }
}

Solution 2:

add below codes in your BroadcastReceiverclass.

publicclassIncomingCallInterceptorReceiverextendsBroadcastReceiver {
@OverridepublicvoidonReceive(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

}
elseif(callingFromSIM =="1"){

    // Incoming call from SIM2 Card 

}

}

}

Solution 3:

Bundlebundle= intent.getExtras();
    Stringstate= 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.

Post a Comment for "Detect Target Phone Number On Incoming Call Is It For Sim 1 Or For Sim 2?"