2012-11-05 136 views
4

我有一個雙卡android手機。我正在使用自定義廣播接收器,它可以毫無問題地讀取傳入的消息。我想知道是否有辦法找出哪個sim收到了這條消息。廣播接收器雙卡

回答

1

您可以使用TelephonyManager獲取活動SIM卡的信息。例如,它是序列號。

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

String simSerial = telephoneMgr.getSimSerialNumber(); 

你也可以得到line1Number,如果你的網絡運營商已經擺在那裏你的號碼,你可以把它比作你就得到了數>在短信領域。

String phoneNumber = telephoneMgr.getLine1Number(); 

希望它可以幫助

+0

首先希望!會試一試。謝謝@marcel –

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

我沒有找到關於此文檔所以這可能是設備/製造商特有的,我可以想像,密鑰是diferent或類似的東西。 您可以通過傾銷包的密鑰集驗證這一點:

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