首页 > 移动平台 > 详细

android监听SIM状态

时间:2015-05-08 16:38:37      阅读:293      评论:0      收藏:0      [点我收藏+]
  1. /* 
  2.      监听sim状态改变的广播,返回sim卡的状态, 有效或者无效。 
  3.     双卡中只要有一张卡的状态有效即返回状态为有效,两张卡都无效则返回无效。 
  4.  */  
  5. import android.app.Service;  
  6. import android.content.BroadcastReceiver;  
  7. import android.content.Context;  
  8. import android.content.Intent;  
  9. import android.telephony.TelephonyManager;  
  10.   
  11. public class SimStateReceive extends BroadcastReceiver {  
  12.     private final static String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";  
  13.     private final static int SIM_VALID = 0;  
  14.     private final static int SIM_INVALID = 1;  
  15.     private int simState = SIM_INVALID;  
  16.       
  17.     public int getSimState() {  
  18.         return simState;  
  19.     }  
  20.   
  21.     @Override  
  22.     public void onReceive(Context context, Intent intent) {  
  23.         if (intent.getAction().equals(ACTION_SIM_STATE_CHANGED)) {  
  24.             TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);   
  25.             int state = tm.getSimState();  
  26.             switch (state) {  
  27.             case TelephonyManager.SIM_STATE_READY :  
  28.                 simState = SIM_VALID;  
  29.                 break;  
  30.             case TelephonyManager.SIM_STATE_UNKNOWN :  
  31.             case TelephonyManager.SIM_STATE_ABSENT :  
  32.             case TelephonyManager.SIM_STATE_PIN_REQUIRED :  
  33.             case TelephonyManager.SIM_STATE_PUK_REQUIRED :  
  34.             case TelephonyManager.SIM_STATE_NETWORK_LOCKED :  
  35.             default:  
  36.                 simState = SIM_INVALID;  
  37.                 break;  
  38.             }  
  39.         }  
  40.     }  
  41.   
  42. }  

android监听SIM状态

原文:http://blog.csdn.net/sweiqin/article/details/45579951

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!