Android 安卓双卡API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11305407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:51:05  来源:igfitidea点击:

Android dual SIM card API

androidsim-card

提问by adam.baker

There are several questions about accessing dual SIM features through the Android SDK, all of which are answered with brief statements that such features are unsupported in Android.

有几个关于通过 Android SDK 访问双 SIM 卡功能的问题,所有这些问题的回答都是简短的声明,这些功能在 Android 中不受支持。

In spite of this, dual SIM phones do exist, and applications like MultiSimseem to be able to detect this in some kind of manufacturer-independent way.

尽管如此,双 SIM 卡手机确实存在,像MultiSim这样的应用程序似乎能够以某种独立于制造商的方式检测到这一点。

So, beginning with that acknowledgement, let me try to ask some more pointed questions:

所以,从这个承认开始,让我试着问一些更尖锐的问题:

  • Does "Android SDK does not support multiple SIM features" mean that these features do not exist, or that it is merely a bad idea to try to use them?
  • Is there an Android content provider or an internal package (com.android...) that provides SIM card information? (TelephonyManager, as far as I can see in the docs and the code, has no mention of multiple SIM cards)
  • Is there any report of any manufacturer exposing multiple SIM features to developers?
  • If I were to look for undocumented functionality from a manufacturer, how would I go about that?
  • “Android SDK 不支持多个 SIM 功能”是否意味着这些功能不存在,或者尝试使用它们只是一个坏主意?
  • 是否有提供 SIM 卡信息的 Android 内容提供商或内部包(com.android...)?(据我在文档和代码中看到的 TelephonyManager 没有提到多个 SIM 卡)
  • 是否有任何制造商向开发人员公开多个 SIM 功能的报告?
  • 如果我要从制造商那里寻找未记录的功能,我会怎么做?

(By the way, the point of all of this is merely to implement this algorithm: send an SMS with SIM card 1; if delivery fails, switch to SIM card 2 and resend the message that way.)

(顺便说一句,这一切的目的只是为了实现这个算法:用SIM卡1发送一条短信;如果发送失败,则切换到SIM卡2并以这种方式重新发送消息。)

采纳答案by mgcaguioa

Android does not support multiple SIM features before API 22. But from Android 5.1 (API level 22) onwards, Android started supporting multiple SIMs. More details on Android Documentation

在 API 22 之前,Android 不支持多 SIM 卡功能。但从 Android 5.1(API 级别 22)开始,Android 开始支持多 SIM 卡。有关Android 文档的更多详细信息

Reference from this Original Answer

来自这个原始答案的参考

回答by Tapa Save

You can use MultiSimlibrary to get details from multi-sim devices.

您可以使用MultiSim库从多卡设备获取详细信息。

Available info from each sim card: IMEI, IMSI, SIM Serial Number, SIM State, SIM operator code, SIM operator name, SIM country iso, network operator code, network operator name, network operator iso, network type, roaming status.

每个SIM卡的可用信息:IMEI、IMSI、SIM序列号、SIM状态、SIM运营商代码、SIM运营商名称、SIM国家iso、网络运营商代码、网络运营商名称、网络运营商iso、网络类型、漫游状态。

Just add the lines below in your app-level Gradle script:

只需在您的应用级 Gradle 脚本中添加以下行:

dependencies {
    compile 'com.kirianov.multisim:multisim:2.0@aar'
}

Don't forget add required permission in AndroidManifest.xml:

不要忘记在 AndroidManifest.xml 中添加所需的权限:

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

Use similar code in your code:

在您的代码中使用类似的代码:

MultiSimTelephonyManager multiSimTelephonyManager = new MultiSimTelephonyManager(this);
// or
MultiSimTelephonyManager multiSimTelephonyManager = new MultiSimTelephonyManager(this, new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    updateInfo();
  }
});


public void updateInfo() {

  // for update UI
  runOnUiThread(new Runnable() {
    @Override
    public void run() {
      multiSimTelephonyManager.update();
      useInfo();
    }
  }

  // for update background information
  multiSimTelephonyManager.update();
  useInfo();
}

public void useInfo() {

  // get number of slots:
  if (multiSimTelephonyManager != null) {
     multiSimTelephonyManager.sizeSlots();
  }

  // get info from each slot:
  if (multiSimTelephonyManager != null) {
    for(int i = 0; i < multiSimTelephonyManager.sizeSlots(); i++) {
      multiSimTelephonyManager.getSlot(i).getImei();
      multiSimTelephonyManager.getSlot(i).getImsi();
      multiSimTelephonyManager.getSlot(i).getSimSerialNumber();
      multiSimTelephonyManager.getSlot(i).getSimState();
      multiSimTelephonyManager.getSlot(i).getSimOperator();
      multiSimTelephonyManager.getSlot(i).getSimOperatorName();
      multiSimTelephonyManager.getSlot(i).getSimCountryIso();
      multiSimTelephonyManager.getSlot(i).getNetworkOperator();
      multiSimTelephonyManager.getSlot(i).getNetworkOperatorName();
      multiSimTelephonyManager.getSlot(i).getNetworkCountryIso();
      multiSimTelephonyManager.getSlot(i).getNetworkType();
      multiSimTelephonyManager.getSlot(i).isNetworkRoaming();
    }
  }
}

// or for devices above android 6.0
MultiSimTelephonyManager multiSimTelephonyManager = new MultiSimTelephonyManager(MyActivity.this, broadcastReceiverChange);

Usage:

用法:

// get info about slot 'i' by methods:
multiSimTelephonyManager.getSlot(i).

Force update info:

强制更新信息:

// force update phone info (needed on devices above android 6.0 after confirm permissions request)
multiSimTelephonyManager.update();

Handle of permissions request (6.0+):

权限请求的处理(6.0+):

// in YourActivity for update info after confirm permissions request on  devices above android 6.0
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (multiSimTelephonyManager != null) {
        multiSimTelephonyManager.update();
    }
}

回答by Gaurav Shah

there are 3 different categories ...

有3个不同的类别...

  1. features supported and documented
  2. Features available and un-documented
  3. features unavailable
  1. 支持和记录的功能
  2. 可用和未记录的功能
  3. 功能不可用

So the dual sim features are available but not documented and hence not officially supported.

所以双卡功能可用但没有记录,因此没有得到官方支持。

Having said that it doesn't mean that it will not be usable , It just means that android(or for that matter google or even manufaturer) is not liable to support your apps functionality.

话虽如此,这并不意味着它不可用,这只是意味着 android(或就此而言 google 甚至制造商)不负责支持您的应用程序功能。

But it might just work , for eg the contacts is a similar thing.

但它可能只是工作,例如联系人是类似的事情。

You might then ask up how would everyone know about the features if in case its not documented.. Hey android is open source .. go look into code and find it for yourself . Thats what I guess the multi sim developers did.

然后,您可能会问,如果没有记录在案,每个人如何知道这些功能。这就是我猜多卡开发商所做的。

回答by Vlad

MultiSim library sources now are not available on VCS
It's sources is still available here https://mvnrepository.com/artifact/com.kirianov.multisim/multisim
I have rewrote it on Kotlin for personal usage

MultiSim 库源现在在 VCS 上不可用
它的源仍然可以在这里获得https://mvnrepository.com/artifact/com.kirianov.multisim/multisim
我已经在 Kotlin 上重写它以供个人使用

class Slot {

    var imei: String? = null

    var imsi: String? = null

    var simState = -1

    val simStates = hashSetOf<Int>()

    var simSerialNumber: String? = null

    var simOperator: String? = null

    var simCountryIso: String? = null

    fun setSimState(state: Int?) {
        if (state == null) {
            simState = -1
            return
        }
        simState = state
    }

    private fun compare(slot: Slot?): Boolean {
        return if (slot != null) {
            imei == slot.imei && imsi == slot.imsi && simSerialNumber == slot.simSerialNumber
        } else false
    }

    fun indexIn(slots: List<Slot>?): Int {
        if (slots == null) {
            return -1
        }
        for (i in slots.indices) {
            if (compare(slots[i])) {
                return i
            }
        }
        return -1
    }

    fun containsIn(slots: List<Slot>?): Boolean {
        if (slots == null) {
            return false
        }
        for (slot in slots) {
            if (compare(slot)) {
                return true
            }
        }
        return false
    }

    override fun toString(): String {
        return "Slot(" +
            "imei=$imei, " +
            "imsi=$imsi, " +
            "simState=$simState, " +
            "simStates=$simStates, " +
            "simSerialNumber=$simSerialNumber, " +
            "simOperator=$simOperator, " +
            "simCountryIso=$simCountryIso" +
            ")"
    }
}

Also i remove native lib dependencies

我还删除了本机库依赖项

import android.Manifest
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.telephony.SubscriptionManager
import android.text.TextUtils
import domain.shadowss.extension.areGranted
import domain.shadowss.extension.isLollipopMR1Plus
import domain.shadowss.extension.isMarshmallowPlus
import domain.shadowss.extension.isOreoPlus
import domain.shadowss.model.Slot
import org.jetbrains.anko.telephonyManager
import timber.log.Timber
import java.lang.ref.WeakReference
import java.lang.reflect.Modifier
import java.util.*

/**
 * https://mvnrepository.com/artifact/com.kirianov.multisim/multisim
 */
@Suppress("MemberVisibilityCanBePrivate")
class MultiSimManager(context: Context) {

    private val reference = WeakReference(context)

    val slots = arrayListOf<Slot>()
        @Synchronized get

    @Suppress("unused")
    val dualMcc: Pair<String?, String?>
        @SuppressLint("MissingPermission")
        @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
        get() = reference.get()?.run {
            if (isLollipopMR1Plus()) {
                if (areGranted(Manifest.permission.READ_PHONE_STATE)) {
                    val subscriptionManager =
                        getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
                    val list = subscriptionManager.activeSubscriptionInfoList
                    return list.getOrNull(0)?.mcc?.toString()
                        ?.padStart(3, '0') to list.getOrNull(1)?.mcc?.toString()
                        ?.padStart(3, '0')
                }
            }
            null to null
        } ?: null to null

    @Synchronized
    @SuppressLint("MissingPermission")
    fun updateData(): String? = reference.get()?.run {
        if (areGranted(Manifest.permission.READ_PHONE_STATE)) {
            val error = try {
                var slotNumber = 0
                while (true) {
                    val slot = touchSlot(slotNumber)
                    if (slot == null) {
                        for (i in slotNumber until slots.size) {
                            slots.removeAt(i)
                        }
                        break
                    }
                    if (slot.containsIn(slots) && slot.indexIn(slots) < slotNumber) {
                        // protect from Alcatel infinity bug
                        break
                    }
                    slots.apply {
                        when {
                            size > slotNumber -> {
                                removeAt(slotNumber)
                                add(slotNumber, slot)
                            }
                            size == slotNumber -> add(slot)
                        }
                    }
                    slotNumber++
                }
                null
            } catch (e: Throwable) {
                Timber.e(e)
                e.toString()
            }
            // below is my custom logic only which was found on practice
            slots.removeAll { it.imsi == null || it.simOperator?.trim()?.isEmpty() != false }
            val imsi = arrayListOf<String?>()
            slots.forEachReversedWithIndex { i, slot ->
                if (imsi.contains(slot.imsi)) {
                    slots.removeAt(i)
                } else {
                    imsi.add(slot.imsi)
                    slot.simStates.apply {
                        clear()
                        addAll(slots.filter { it.imsi == slot.imsi }.map { it.simState })
                    }
                }
            }
            error
        } else {
            slots.clear()
            null
        }
    }

    @Suppress("SpellCheckingInspection", "DEPRECATION")
    @SuppressLint("MissingPermission", "HardwareIds")
    private fun touchSlot(slotNumber: Int): Slot? = reference.get()?.run {
        val slot = Slot()
        val telephonyManager = telephonyManager
        Timber.v("telephonyManager [$telephonyManager] ${telephonyManager.deviceId}")
        val subscriberIdIntValue = ArrayList<String>()
        val subscriberIdIntIndex = ArrayList<Int>()
        for (i in 0..99) {
            val subscriber = runMethodReflect(
                telephonyManager,
                "android.telephony.TelephonyManager",
                "getSubscriberId",
                arrayOf(i),
                null
            ) as? String
            if (subscriber != null && !subscriberIdIntValue.contains(subscriber)) {
                subscriberIdIntValue.add(subscriber)
                subscriberIdIntIndex.add(i)
            }
        }
        var subIdInt =
            if (subscriberIdIntIndex.size > slotNumber) subscriberIdIntIndex[slotNumber] else null
        if (subIdInt == null) {
            try {
                subIdInt = runMethodReflect(
                    telephonyManager,
                    "android.telephony.TelephonyManager",
                    "getSubId",
                    arrayOf(slotNumber),
                    null
                ).toString().toInt()
            } catch (ignored: Throwable) {
            }
        }
        Timber.v("subIdInt $subIdInt")
        val subscriberIdLongValue = ArrayList<String>()
        val subscriberIdLongIndex = ArrayList<Long>()
        for (i in 0L until 100L) {
            val subscriber = runMethodReflect(
                telephonyManager,
                "android.telephony.TelephonyManager",
                "getSubscriberId",
                arrayOf(i),
                null
            ) as? String
            runMethodReflect(
                telephonyManager,
                "android.telephony.TelephonyManagerSprd",
                "getSubInfoForSubscriber",
                arrayOf(i),
                null
            ) ?: continue
            if (subscriber != null && !subscriberIdLongValue.contains(subscriber)) {
                subscriberIdLongValue.add(subscriber)
                subscriberIdLongIndex.add(i)
            }
        }
        if (subscriberIdLongIndex.size <= 0) {
            for (i in 0L until 100L) {
                val subscriber = runMethodReflect(
                    telephonyManager,
                    "android.telephony.TelephonyManager",
                    "getSubscriberId",
                    arrayOf(i),
                    null
                ) as? String
                if (subscriber != null && !subscriberIdLongValue.contains(subscriber)) {
                    subscriberIdLongValue.add(subscriber)
                    subscriberIdLongIndex.add(i)
                }
            }
        }
        var subIdLong =
            if (subscriberIdLongIndex.size > slotNumber) subscriberIdLongIndex[slotNumber] else null
        if (subIdLong == null) {
            subIdLong = runMethodReflect(
                telephonyManager,
                "android.telephony.TelephonyManager",
                "getSubId",
                arrayOf(slotNumber),
                null
            ) as? Long
        }
        Timber.v("subIdLong $subIdLong")
        val listParamsSubs = ArrayList<Any?>()
        if (subIdInt != null && !listParamsSubs.contains(subIdInt)) {
            listParamsSubs.add(subIdInt)
        }
        if (subIdLong != null && !listParamsSubs.contains(subIdLong)) {
            listParamsSubs.add(subIdLong)
        }
        if (!listParamsSubs.contains(slotNumber)) {
            listParamsSubs.add(slotNumber)
        }
        val objectParamsSubs = listParamsSubs.toTypedArray()
        for (i in objectParamsSubs.indices) {
            Timber.v("SPAM PARAMS_SUBS [$i]=[${objectParamsSubs[i]}]")
        }
        val listParamsSlot = ArrayList<Any?>()
        if (!listParamsSlot.contains(slotNumber)) {
            listParamsSlot.add(slotNumber)
        }
        if (subIdInt != null && !listParamsSlot.contains(subIdInt)) {
            listParamsSlot.add(subIdInt)
        }
        if (subIdLong != null && !listParamsSlot.contains(subIdLong)) {
            listParamsSlot.add(subIdLong)
        }
        val objectParamsSlot = listParamsSlot.toTypedArray()
        for (i in objectParamsSlot.indices) {
            Timber.v("SPAM PARAMS_SLOT [$i]=[${objectParamsSlot[i]}]")
        }
        // firstly all Int params, then all Long params
        Timber.v("------------------------------------------")
        Timber.v("SLOT [$slotNumber]")
        if (isMarshmallowPlus()) {
            slot.imei = telephonyManager.getDeviceId(slotNumber)
        }
        if (slot.imei == null) {
            slot.imei = iterateMethods("getDeviceId", objectParamsSlot) as? String
        }
        if (slot.imei == null) {
            slot.imei = runMethodReflect(
                null,
                "com.android.internal.telephony.Phone",
                null,
                null,
                "GEMINI_SIM_" + (slotNumber + 1)
            ) as? String
        }
        if (slot.imei == null) {
            slot.imei = runMethodReflect(
                getSystemService("phone" + (slotNumber + 1)),
                null,
                "getDeviceId",
                null,
                null
            ) as? String
        }
        Timber.v("IMEI [${slot.imei}]")
        if (slot.imei == null) {
            when (slotNumber) {
                0 -> {
                    slot.imei = if (isOreoPlus()) {
                        telephonyManager.imei
                    } else {
                        telephonyManager.deviceId
                    }
                    slot.imsi = telephonyManager.subscriberId
                    slot.simState = telephonyManager.simState
                    slot.simOperator = telephonyManager.simOperator
                    slot.simSerialNumber = telephonyManager.simSerialNumber
                    slot.simCountryIso = telephonyManager.simCountryIso
                    return slot
                }
            }
        }
        if (slot.imei == null) {
            return null
        }
        slot.setSimState(iterateMethods("getSimState", objectParamsSlot) as? Int)
        Timber.v("SIMSTATE [${slot.simState}]")
        slot.imsi = iterateMethods("getSubscriberId", objectParamsSubs) as? String
        Timber.v("IMSI [${slot.imsi}]")
        slot.simSerialNumber = iterateMethods("getSimSerialNumber", objectParamsSubs) as? String
        Timber.v("SIMSERIALNUMBER [${slot.simSerialNumber}]")
        slot.simOperator = iterateMethods("getSimOperator", objectParamsSubs) as? String
        Timber.v("SIMOPERATOR [${slot.simOperator}]")
        slot.simCountryIso = iterateMethods("getSimCountryIso", objectParamsSubs) as? String
        Timber.v("SIMCOUNTRYISO [${slot.simCountryIso}]")
        Timber.v("------------------------------------------")
        return slot
    }

    @SuppressLint("WrongConstant")
    private fun iterateMethods(methodName: String?, methodParams: Array<Any?>): Any? =
        reference.get()?.run {
            if (methodName == null || methodName.isEmpty()) {
                return null
            }
            val telephonyManager = telephonyManager
            val instanceMethods = ArrayList<Any?>()
            val multiSimTelephonyManagerExists = telephonyManager.toString()
                .startsWith("android.telephony.MultiSimTelephonyManager")
            for (methodParam in methodParams) {
                if (methodParam == null) {
                    continue
                }
                val objectMulti = if (multiSimTelephonyManagerExists) {
                    runMethodReflect(
                        null,
                        "android.telephony.MultiSimTelephonyManager",
                        "getDefault",
                        arrayOf(methodParam),
                        null
                    )
                } else {
                    telephonyManager
                }
                if (!instanceMethods.contains(objectMulti)) {
                    instanceMethods.add(objectMulti)
                }
            }
            if (!instanceMethods.contains(telephonyManager)) {
                instanceMethods.add(telephonyManager)
            }
            val telephonyManagerEx = runMethodReflect(
                null,
                "com.mediatek.telephony.TelephonyManagerEx",
                "getDefault",
                null,
                null
            )
            if (!instanceMethods.contains(telephonyManagerEx)) {
                instanceMethods.add(telephonyManagerEx)
            }
            val phoneMsim = getSystemService("phone_msim")
            if (!instanceMethods.contains(phoneMsim)) {
                instanceMethods.add(phoneMsim)
            }
            if (!instanceMethods.contains(null)) {
                instanceMethods.add(null)
            }
            var result: Any?
            for (methodSuffix in suffixes) {
                for (className in classNames) {
                    for (instanceMethod in instanceMethods) {
                        for (methodParam in methodParams) {
                            if (methodParam == null) {
                                continue
                            }
                            result = runMethodReflect(
                                instanceMethod,
                                className,
                                methodName + methodSuffix,
                                if (multiSimTelephonyManagerExists) null else arrayOf(methodParam),
                                null
                            )
                            if (result != null) {
                                return result
                            }
                        }
                    }
                }
            }
            return null
        }

    private fun runMethodReflect(
        instanceInvoke: Any?,
        classInvokeName: String?,
        methodName: String?,
        methodParams: Array<Any>?,
        field: String?
    ): Any? {
        var result: Any? = null
        try {
            val classInvoke = when {
                classInvokeName != null -> Class.forName(classInvokeName)
                instanceInvoke != null -> instanceInvoke.javaClass
                else -> return null
            }
            if (field != null) {
                val fieldReflect = classInvoke.getField(field)
                val accessible = fieldReflect.isAccessible
                fieldReflect.isAccessible = true
                result = fieldReflect.get(null).toString()
                fieldReflect.isAccessible = accessible
            } else {
                var classesParams: Array<Class<*>?>? = null
                if (methodParams != null) {
                    classesParams = arrayOfNulls(methodParams.size)
                    for (i in methodParams.indices) {
                        classesParams[i] = when {
                            methodParams[i] is Int -> Int::class.javaPrimitiveType
                            methodParams[i] is Long -> Long::class.javaPrimitiveType
                            methodParams[i] is Boolean -> Boolean::class.javaPrimitiveType
                            else -> methodParams[i].javaClass
                        }
                    }
                }
                val method = if (classesParams != null) {
                    classInvoke.getDeclaredMethod(methodName.toString(), *classesParams)
                } else {
                    classInvoke.getDeclaredMethod(methodName.toString())
                }
                val accessible = method.isAccessible
                method.isAccessible = true
                result = if (methodParams != null) {
                    method.invoke(instanceInvoke ?: classInvoke, *methodParams)
                } else {
                    method.invoke(instanceInvoke ?: classInvoke)
                }
                method.isAccessible = accessible
            }
        } catch (ignored: Throwable) {
        }
        return result
    }

    @Suppress("unused")
    val allMethodsAndFields: String
        get() = """
            Default: ${reference.get()?.telephonyManager}${'\n'}
            ${printAllMethodsAndFields("android.telephony.TelephonyManager")}
            ${printAllMethodsAndFields("android.telephony.MultiSimTelephonyManager")}
            ${printAllMethodsAndFields("android.telephony.MSimTelephonyManager")}
            ${printAllMethodsAndFields("com.mediatek.telephony.TelephonyManager")}
            ${printAllMethodsAndFields("com.mediatek.telephony.TelephonyManagerEx")}
            ${printAllMethodsAndFields("com.android.internal.telephony.ITelephony")}
        """.trimIndent()

    private fun printAllMethodsAndFields(className: String): String {
        val builder = StringBuilder()
        builder.append("========== $className\n")
        try {
            val cls = Class.forName(className)
            for (method in cls.methods) {
                val params = method.parameterTypes.map { it.name }
                builder.append(
                    "M: ${method.name} [${params.size}](${TextUtils.join(
                        ",",
                        params
                    )}) -> ${method.returnType} ${if (Modifier.isStatic(method.modifiers)) "(static)" else ""}\n"
                )
            }
            for (field in cls.fields) {
                builder.append("F: ${field.name} ${field.type}\n")
            }
        } catch (e: Throwable) {
            builder.append("E: $e\n")
        }
        return builder.toString()
    }

    companion object {

        private val classNames = arrayOf(
            null,
            "android.telephony.TelephonyManager",
            "android.telephony.MSimTelephonyManager",
            "android.telephony.MultiSimTelephonyManager",
            "com.mediatek.telephony.TelephonyManagerEx",
            "com.android.internal.telephony.Phone",
            "com.android.internal.telephony.PhoneFactory"
        )

        private val suffixes = arrayOf(
            "",
            "Gemini",
            "Ext",
            "Ds",
            "ForSubscription",
            "ForPhone"
        )
    }
}

May be it wiil be helpful for somebody

可能对某人有帮助

回答by Vaishali Sutariya

 <receiver
     android:name=".SimChangedReceiver"
    android:enabled="true"
    android:process=":remote" >
    <intent-filter>
        <action android:name="android.intent.action.SIM_STATE_CHANGED" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
 </receiver>

SimChangedReceiver class

public class SimChangedReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equalsIgnoreCase("android.intent.action.SIM_STATE_CHANGED")) {
        Log.d("SimChangedReceiver", "--> SIM state changed <--");   

      //            do code  whatever u want to apply action                //

    }
   }
}

this is work for dual sim also , and you don't need to call this receiver because it will run remotely

这也适用于双卡,你不需要打电话给这个接收器,因为它会远程运行