How can I check whether the Sim Card is available in an android device?

前端 未结 3 1622
-上瘾入骨i
-上瘾入骨i 2020-11-27 13:58

I need help checking whether a device has a sim card programatically. Please provide sample code.

3条回答
  •  春和景丽
    2020-11-27 14:57

    Found another way to do this.

    public static boolean isSimStateReadyorNotReady() {
            int simSlotCount = sSlotCount;
            String simStates = SystemProperties.get("gsm.sim.state", "");
            if (simStates != null) {
                String[] slotState = simStates.split(",");
                int simSlot = 0;
                while (simSlot < simSlotCount && slotState.length > simSlot) {
                    String simSlotState = slotState[simSlot];
                    Log.d("MultiSimUtils", "isSimStateReadyorNotReady() : simSlot = " + simSlot + ", simState = " + simSlotState);
                    if (simSlotState.equalsIgnoreCase("READY") || simSlotState.equalsIgnoreCase("NOT_READY")) {
                        return true;
                    }
                    simSlot++;
                }
            }
            return false;
        }
    

提交回复
热议问题