我是靠谱客的博主 受伤飞机,这篇文章主要介绍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;

}

}

}

}

最后

以上就是受伤飞机最近收集整理的关于android sim卡状态改变广播,android监控SIM卡状态的广播示例代码的全部内容,更多相关android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部