android SIM卡状态
2016-07-21 11:35
302 查看
[java]
view plain
copy
print?
/*
监听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;
}
}
}
}
view plain
copy
print?
/*
监听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照相机Camera
- 百度地图API使用的一些注意事项
- [置顶] Android Studio 如何导出和导入自己的常用设置,避免重复制造轮子。加快开发速度
- 超酷炫的Android碎纸机效果推荐
- apkprotect(免费android代码混淆、加密保护工具) Android中的Apk的加固(加壳)原理解析和实现
- Menu的设定
- 教大家如何修改ionic中android程序的包名
- Android 之 RecyclerView 连续移除Item报错
- Android输出Log优化
- 自己动手写消息机制
- AndroidStudio 下SVN的使用
- Android PopupMenu和PopupWindow
- Android内存测试
- Android源码是如何自动生成apk文件的
- Android和iOS知识结构
- Android Studio快捷键整理
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- Android之Toast自定义动画
- 浅谈 MVP in Android
- [android]我是这样写自定义Dialog的