android sim卡状态改变广播,android监控SIM卡状态的广播示例代码

/*

监听sim状态改变的广播,返回sim卡的状态, 有效或者无效。

双卡中只要有一张卡的状态有效即返回状态为有效,两张卡都无效则返回无效。

*/

import android.app.Service;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.telephony.TelephonyManager;

public class SimStateReceive extends BroadcastReceiver {

private final static String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";

private final static int SIM_VALID = 0;

private final static int SIM_INVALID = 1;

private int simState = SIM_INVALID;

public int getSimState() {

return simState;

}

@Override

public void onReceive(Context context, Intent intent) {

System.out.println("sim state changed");

if (intent.getAction().equals(ACTION_SIM_STATE_CHANGED)) {

TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);

int state = tm.getSimState();

switch (state) {

case TelephonyManager.SIM_STATE_READY :

simState = SIM_VALID;

break;

case TelephonyManager.SIM_STATE_UNKNOWN :

case TelephonyManager.SIM_STATE_ABSENT :

case TelephonyManager.SIM_STATE_PIN_REQUIRED :

case TelephonyManager.SIM_STATE_PUK_REQUIRED :

case TelephonyManager.SIM_STATE_NETWORK_LOCKED :

default:

simState = SIM_INVALID;

break;

}

}

}

}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com

特别注意:本站所有转载文章言论不代表本站观点!

本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值