簡體   English   中英

在 Multi-Sim 設備中檢測來電的目標 SimCard

[英]Detecting target SimCard of incoming call in Multi-Sim devices

我閱讀了很多帖子並嘗試了許多解決方案,但所有帖子的共同點是它們都已過時,至少我找不到適用於較新版本的 Android 的解決方案。

發布 1 ,結果: intent.getExtras().getInt("simId", -1)總是返回 -1

發布 2 ,結果: intent.getExtras().getInt("slot", -1)總是返回 -1

發布 3 ,結果:

String[] array = new String[]{
        "extra_asus_dial_use_dualsim",
        "com.android.phone.extra.slot",
        "slot",
        "simslot",
        "sim_slot",
        "subscription",
        "Subscription",
        "phone",
        "com.android.phone.DialingMode",
        "simSlot",
        "slot_id",
        "simId",
        "simnum",
        "phone_type",
        "slotId",
        "slotIdx"
};

for (String item :
        array) {
    Log.i(TAG, "Sim Card - " + item + " -----> " + intent.getExtras().getInt(item));
}

日志:

PhoneCallReceiver: Sim Card - extra_asus_dial_use_dualsim -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.extra.slot -----> 0
PhoneCallReceiver: Sim Card - slot -----> 0
PhoneCallReceiver: Sim Card - simslot -----> 0
PhoneCallReceiver: Sim Card - sim_slot -----> 0
PhoneCallReceiver: Sim Card - subscription -----> 0
PhoneCallReceiver: Sim Card - Subscription -----> 0
PhoneCallReceiver: Sim Card - phone -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.DialingMode -----> 0
PhoneCallReceiver: Sim Card - simSlot -----> 0
PhoneCallReceiver: Sim Card - slot_id -----> 0
PhoneCallReceiver: Sim Card - simId -----> 0
PhoneCallReceiver: Sim Card - simnum -----> 0
PhoneCallReceiver: Sim Card - phone_type -----> 0
PhoneCallReceiver: Sim Card - slotId -----> 0
PhoneCallReceiver: Sim Card - slotIdx -----> 0

它為第一個 SimCard 和第二個 SimCard 顯示具有相同值 0 的相同日志。

我也嘗試過其他類似的帖子。 沒有人適用於新版本的android!

是否有另一種適用於較新版本的 Android(7.0 或更高版本)的解決方案?

如果你這樣做了,它應該可以工作。 確保您的測試設備在 Android 5.1 或更高版本上運行。 在 v 5.1 中添加了雙 sim 卡支持( 在此處查看)

public class IncomingCallInterceptor extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    String callingSIM = "";
    Bundle bundle = intent.getExtras();
    callingSIM = String.valueOf(bundle.getInt("simId", -1));

    if(callingSIM.equals("0")){
           // Incoming call from SIM1
        } else if(callingSIM.equals("1")){
           // Incoming call from SIM2
        }
    }
}

確保您在清單中添加了以下權限

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

筆記:

這些值不需要一直出現。 需要網絡提供商支持。請閱讀此處的文檔

當前訂閱的運營商 ID。 如果訂閱不可用或無法識別運營商,則返回 UNKNOWN_CARRIER_ID。

正式地,意圖提供的唯一記錄值是電話號碼。

一些構造函數在意圖中添加了其他值,例如 sim 插槽號,但這不是強制性的。 這就是為什么有這么多槽鍵名稱可能的原因,就像帖子 3中介紹的那樣,每個構造函數都添加了自己的實現。

也有可能某些構造函數沒有在某些模型中添加此值,您的 model 肯定就是這種情況。 如果構造函數不提供該值,則無法找到該值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM