最近由于一个sim卡相关的需求,就去了解了一下Android Sim卡相关的一些代码.在此记录一下.
简要说一下需求吧,需要在插拔卡的时候弹出对话框,提供界面让用户选择开启默认卡数据链接或者转移到另一张卡开启数据链接.
这个主要就是监听sim卡的状态.sim卡的状态.一般网上搜到的都是广播--"android.intent.action.SIM_STATE_CHANGED"
简要说一下需求吧,需要在插拔卡的时候弹出对话框,提供界面让用户选择开启默认卡数据链接或者转移到另一张卡开启数据链接.
这个主要就是监听sim卡的状态.sim卡的状态.一般网上搜到的都是广播--"android.intent.action.SIM_STATE_CHANGED"
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_STA