Dual Sim Broadcast Receiver

I have a dual sim phone for Android. I use my own broadcast receiver, which reads incoming messages without problems. I wonder if there is a way to find out which sim received the message.

+4
source share
2 answers

You can get active information about the sim using TelephonyManager. For example, this is a serial number.

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

You can also get the string 1Number, if your network operator has placed your number there, you can compare it with the number that you received in the> field in the SMS message.

 String phoneNumber = telephoneMgr.getLine1Number(); 

Hope this helps

+1
source

I had a very hard time with this problem, and finally I found a solution, although I only tested it above level 22 api.

You should look at additional information in the intent received. In my case, there are two keys in the optional intent bundle that are useful: “slot” and “subscription”.

Here is an example:

 public class IncomingSms extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. Bundle bundle = intent.getExtras(); int slot = bundle.getInt("slot", -1); int sub = bundle.getInt("subscription", -1); /* Handle the sim info */ } } 

I did not find documentation about this, so it may be device / manufacturer dependent, I can imagine that the keys are different or something like that. You can verify this by resetting the key set:

 Set<string> keyset = bundle.keySet(); 
0
source

Source: https://habr.com/ru/post/1444104/


All Articles