Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to figure out which SIM received SMS in Dual SIM Android Device

I'm working on a project to sync sms received in a Android phone to a online database. I can get sender's number by calling getOriginatingAddress() method. But I can't find any solution to figure out which SIM in my device received the sms.

I searched the web about it, but couldn't find a way to figure this out. Is there any way to get SMS receiver's number?

like image 365
haider_kazal Avatar asked Mar 13 '16 09:03

haider_kazal


People also ask

How do you know which number is being called on Dual SIM?

When a call is received you should see a letter in a box below the name of the person or number that is calling. This icon corresponds with the first letter of the label you assigned to the phone number receiving the call.

How do I find out which SIM is receiving the incoming call in an Android Dual SIM phone?

One of the means to detect the incoming call is to use the PhoneStateListener class (instead of using a receiver) to detect change in phone states. The PhoneStateListener in these phones are modified (rather than subclassed) to include a mSubscription field which should indicate the SIM slot of the listener.

How do I know if my message is SIM 1 or 2?

Just simply open the message for which want to know it's receiving sim, there at top of the message it will be written 1 or 2. 1 means sim in the slot one recived the message and 2 for sim in slot 2.


2 Answers

I achieved a very good result by combining the answers and updating

    private String detectSim(Bundle bundle) {
    int slot = -1;
    Set<String> keySet = bundle.keySet();
    for (String key : keySet)
    {
        switch (key) {
            case "phone":
                slot = bundle.getInt("phone", -1);
                break;
            case "slot":
                slot = bundle.getInt("slot", -1);
                break;
            case "simId":
                slot = bundle.getInt("simId", -1);
                break;
            case "simSlot":
                slot = bundle.getInt("simSlot", -1);
                break;
            case "slot_id":
                slot = bundle.getInt("slot_id", -1);
                break;
            case "simnum":
                slot = bundle.getInt("simnum", -1);
                break;
            case "slotId":
                slot = bundle.getInt("slotId", -1);
                break;
            case "slotIdx":
                slot = bundle.getInt("slotIdx", -1);
                break;
            default:
                if (key.toLowerCase().contains("slot") | key.toLowerCase().contains("sim")) {
                    String value = bundle.getString(key, "-1");
                    if (value.equals("0") | value.equals("1") | value.equals("2")) {
                        slot = bundle.getInt(key, -1);
                    }
                }
        }
    }

    Log.d("KKK",String.valueOf(slot));

    if (slot==0)
    {
        return "sim1";
    }
    else if (slot==1)
    {
        return "sim2";
    }
    else
    {
        return "undetected";
    }
}
like image 137
mahmood.karimizade Avatar answered Nov 15 '22 18:11

mahmood.karimizade


I used Levente Püsök 's answer with a little change. But I did not test on all devices.

try {
Bundle bundle = intent.getExtras();
int slot = -1;
if (bundle != null) {
Set<String> keySet = bundle.keySet();
for(String key:keySet){
  switch (key){
    case "slot":slot = bundle.getInt("slot", -1);
    break;
    case "simId":slot = bundle.getInt("simId", -1);
    break;
    case "simSlot":slot = bundle.getInt("simSlot", -1);
    break;
    case "slot_id":slot = bundle.getInt("slot_id", -1);
    break;
    case "simnum":slot = bundle.getInt("simnum", -1);
    break;
    case "slotId":slot = bundle.getInt("slotId", -1);
    break;
    case "slotIdx":slot = bundle.getInt("slotIdx", -1);
    break;
    default:
      if(key.toLowerCase().contains("slot")|key.toLowerCase().contains("sim")){
       String value = bundle.getString(key, "-1");
       if(value.equals("0")|value.equals("1")|value.equals("2")){
         slot = bundle.getInt(key, -1);
       }
    }


  }
}

 Log.d("slot", "slot=>"+slot);

 }

}catch (Exception e){
Log.d(TAG, "Exception=>"+e);
 }
like image 42
Mikael Avatar answered Nov 15 '22 18:11

Mikael