检测收的sim卡的状态,并调用系统的打电话功能

来源:互联网 发布:ubuntu卸载qq国际版 编辑:程序博客网 时间:2024/04/30 10:05

1.首先创建变量 

private TelephonyManager mTelephonyManager;

 private String mString = "";

2、

 //判断sim卡的状态
 public void Checksimcard() {

  mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  int simState = mTelephonyManager.getSimState();

  switch (simState) {

  case TelephonyManager.SIM_STATE_ABSENT:

   mString = "无卡";

   break;

  case TelephonyManager.SIM_STATE_NETWORK_LOCKED:

   mString = "需要NetworkPIN解锁";

   break;

  case TelephonyManager.SIM_STATE_PIN_REQUIRED:

   mString = "需要PIN解锁";

   break;

  case TelephonyManager.SIM_STATE_PUK_REQUIRED:

   mString = "需要PUN解锁";

   break;

  case TelephonyManager.SIM_STATE_READY:

   mString = "良好";

   break;

  case TelephonyManager.SIM_STATE_UNKNOWN:

   mString = "未知状态";

   break;

  }

 }

3、

// 系统的打电话
     Intent intent = new Intent(Intent.ACTION_CALL,
       Uri.parse("tel:" + telephonnum));
     startActivity(intent);

4、调用系统的拨号盘

// 系统的打电话
     Intent telephonedial = new Intent(Intent.ACTION_CALL_BUTTON);
     startActivity(telephonedial);

5.添加权限

  <!-- 拨打电话的权限 -->
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CALL_PRIVILEGED" />