释放双眼,带上耳机,听听看~!
/*
监听sim状态改变的广播,返回sim卡的状态,有效或者无效。
双卡中只要有一张卡的状态有效即返回状态为有效,两张卡都无效则返回无效。
*/
importandroid.app.Service;
importandroid.content.BroadcastReceiver;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.telephony.TelephonyManager;
publicclassSimStateReceiveextendsBroadcastReceiver{
privatefinalstaticStringACTION_SIM_STATE_CHANGED="android.intent.action.SIM_STATE_CHANGED";
privatefinalstaticintSIM_VALID=0;
privatefinalstaticintSIM_INVALID=1;
privateintsimState=SIM_INVALID;
publicintgetSimState(){
returnsimState;
}
@Override
publicvoidonReceive(Contextcontext,Intentintent){
if(intent.getAction().equals(ACTION_SIM_STATE_CHANGED)){
TelephonyManagertm=(TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
intstate=tm.getSimState();
switch(state){
caseTelephonyManager.SIM_STATE_READY:
simState=SIM_VALID;
break;
caseTelephonyManager.SIM_STATE_UNKNOWN:
caseTelephonyManager.SIM_STATE_ABSENT:
caseTelephonyManager.SIM_STATE_PIN_REQUIRED:
caseTelephonyManager.SIM_STATE_PUK_REQUIRED:
caseTelephonyManager.SIM_STATE_NETWORK_LOCKED:
default:
simState=SIM_INVALID;
break;
}
}
}
}