如何监控 SIM 卡状态变化 [英] How to monitor SIM state change

查看:36
本文介绍了如何监控 SIM 卡状态变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在 SIM 状态改变时做一些事情,即在需要 SIM PIN 时播放声音,但我认为没有广播事件可以被广播接收器拦截.. 注册 android.intent.action.PHONE_STATE 只会在 CALL-STATE 更改时告诉您.. 另一种方法是启动注册 PhoneStateListener 的服务并对其做出反应一个 LISTEN_SERVICE_STATE(当状态为 OUT-OF-STATE 时,它可以从 TelephonyManager 获取 SIM 状态并查看状态是否为 SIM_STATE_PIN_REQUIRED).所以,我的问题是:

I'd like to be able to do some stuff when the SIM state change, i.e. play a sound when SIM PIN is required, but I think there are no Broadcast events that can be intercepted by a broadcast receiver for this... registering for android.intent.action.PHONE_STATE does only tell you when the CALL-STATE changes.. An alternative can be starting a service that registers a PhoneStateListener and reacts upon a LISTEN_SERVICE_STATE (when the state is OUT-OF-STATE it can get the SIM state from the TelephonyManager and look if the state is SIM_STATE_PIN_REQUIRED). So, my questions are:

1) 是否有任何广播 Intent 可用于拦截 SIM 状态更改或服务状态更改?

1) Is there any broadcast intent that I can use to intercept a SIM state change or a Service State change?

2) 在服务中安装 PhoneStateListener 并在收到电话状态更改通知后使用它向服务本身传递意图是不是一个坏主意通过 PhoneStateListener?

2) is it a bad idea to install a PhoneStateListener within a Service and use it to deliver intents to the Service itself upon the notification of a phone state changed received by the PhoneStateListener?

推荐答案

Intent android.intent.action.SIM_STATE_CHANGED 在 SIM 状态改变时广播.例如,在带有 T-Mobile SIM 卡的 HTC Desire 上,如果我将设备置于飞行模式,则会广播以下 Intent:

The Intent android.intent.action.SIM_STATE_CHANGED is broadcast when the SIM state changes. For example, on my HTC Desire with a T-Mobile SIM card, if I put the device into flight mode the following Intent is broadcast:

  • 意图:android.intent.action.SIM_STATE_CHANGED 附加:ss = NOT_READY,reason = null

如果我将其退出飞行模式,则会广播以下 Intent:

If I then take it out of flight mode, the following Intents are broadcast:

  • 意图:android.intent.action.SIM_STATE_CHANGED 附加:ss = LOCKED,reason = PIN
  • 意图:android.intent.action.SIM_STATE_CHANGED 附加:ss = READY,reason = null
  • 意图:android.intent.action.SIM_STATE_CHANGED 与附加:ss = IMSI,原因 = null
  • 意图:android.intent.action.SIM_STATE_CHANGED 附加:ss = LOADED,reason = null

不同的制造商和不同型号的行为可能会有所不同.正如他们所说,您的里程可能会有所不同".

It is possible that different manufacturers and different models behave differently. As they say, "Your mileage may vary".

这篇关于如何监控 SIM 卡状态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆