广播接收器Dual Sim

时间:2012-11-05 12:40:31

标签: android broadcastreceiver dual-sim

我有一个双卡通Android手机。我正在使用自定义广播接收器,它可以毫无问题地读取传入的消息。我想知道是否有办法找出哪个SIM收到了这条消息。

2 个答案:

答案 0 :(得分:1)

您可以使用TelephonyManager获取活动的SIM卡信息。例如,它是序列号。

TelephonyManager telephoneMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

String simSerial = telephoneMgr.getSimSerialNumber();

您也可以获取line1Number,如果您的网络运营商已将您的号码放在那里,您可以将其与您在其上获得的号码进行比较>短信中的字段。

String phoneNumber = telephoneMgr.getLine1Number();

希望有所帮助

答案 1 :(得分:0)

我有一些非常困难的时间来解决这个问题,最后我找到了一个解决方案,尽管我只在api 22级以上进行了测试。

您必须查看收到的意图中的额外信息。在我的情况下,意图的额外Bundle中有两个键是有用的:“slot”和“subscription”。

以下是示例:

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
                */
            }
}

我没有找到关于此的文档,所以这可能是设备/制造商的依赖,我可以想象键是不同的或类似的东西。 您可以通过转储捆绑包的密钥集来验证这一点:

Set<string> keyset = bundle.keySet();
相关问题