Search code examples
androidbroadcastreceiverdual-sim

Broadcast Receiver Dual Sim


I have a dual sim android phone. I am using a custom broadcast receiver which reads incoming messages with no problem. I wonder if there is a way to find out which sim received the message.


Solution

  • You can get the active sim's info by using TelephonyManager. FOr example, it's serial number.

    TelephonyManager telephoneMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    
    String simSerial = telephoneMgr.getSimSerialNumber();
    

    You could also get the line1Number, if your network operator has put your number in there, you could compare it to the number you got on the to> field in the SMS message.

    String phoneNumber = telephoneMgr.getLine1Number();
    

    Hope it helps