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?
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.
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.
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.
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";
}
}
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With