gpt4 book ai didi

android - 更换 SIM 卡时的事件

转载 作者:可可西里 更新时间:2023-11-01 18:50:22 27 4
gpt4 key购买 nike

手机换卡时如何访问事件?

最佳答案

基本上,这个问题“How to monitor SIM state change”的答案也是您问题的正确答案。

所以你创建了一个新类

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.
}
}

并调整您的 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>

像往常一样,在 Android 上,不保证它在任何版本或任何制造商的设备上都能正常工作。

关于android - 更换 SIM 卡时的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5389512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com