更换SIM卡时的事件

sha*_*kar 15 android

如何在移动设备中更改SIM卡时访问事件?

Chr*_*oph 17

基本上,这个问题" 如何监控SIM状态变化 "的答案也是你问题的正确答案.

所以你创建了一个新类

package a.b.c;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class SimChangedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, final Intent intent) {

         Log.d("SimChangedReceiver", "--> SIM state changed <--");

        // Most likely, checking if the SIM changed could be limited to
        // events where the intent's extras contains a key "ss" with value "LOADED".
        // But it is more secure to just always check if there was a change.
    }
}
Run Code Online (Sandbox Code Playgroud)

并调整你的AndroidManifest.xml包含

<!-- put this where your other permissions are: -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- and -->
<application
    android:name="a.b.c...."
    ... >
    <!-- put this somewhere into your application section: -->
    <receiver android:name="a.b.c.SimChangedReceiver">
        <intent-filter>
            <action android:name="android.intent.action.SIM_STATE_CHANGED"/>
        </intent-filter>
    </receiver>
</application>
Run Code Online (Sandbox Code Playgroud)

像往常一样在Android上,不保证它适用于任何版本或任何制造商的设备.


Oll*_*e C 10

我不知道某个事件,但是当交换SIM时手机将被关闭然后打开,因此您可以创建一个服务,将SIM序列号存储在首选项中,然后比较存储的序列号和服务启动时的当前SIM卡.

以下是访问SIM卡详细信息的详细信息: 使用Android应用程序访问SIM卡?

  • 在某些型号中,可以在不转动手机的情况下弹出SIM卡. (8认同)
  • 是的,在Galaxy Nexus上,您可以在运行时移除SIM卡.如果在运行时插入新SIM卡,则在重新通电后才会生效.从电话管理器获取号码将返回null /空字符串. (2认同)

jan*_*ovd 7

保存最新的SIM ID,每次手机从AirplaneModeON状态转到AirplaneModeOFF时,检查新的SIM ID是否与之前保存的SIM ID相同.

检查此答案以了解如何检测飞行模式.

我希望这能回答你的问题.