900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > android sim卡状态改变广播 android监听SIM状态

android sim卡状态改变广播 android监听SIM状态

时间:2018-09-09 20:16:11

相关推荐

android sim卡状态改变广播 android监听SIM状态

释放双眼,带上耳机,听听看~!

/*

监听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;

}

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。