Android获取以编程方式解锁SIM的尝试次数

时间:2014-09-18 09:38:45

标签: java android gsm telephony

我通过我的应用程序通过这些行动态解锁SIM PIN

TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();

if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
  try {

   @SuppressWarnings("rawtypes")
   Class clazz = Class.forName(manager.getClass().getName());

   Method m = clazz.getDeclaredMethod("getITelephony");
   m.setAccessible(true);
   ITelephony it = (ITelephony) m.invoke(manager);
   if (it.supplyPin(simPin)) {
       Toast.makeText(context,"SIM UnLocked",Toast.LENGTH_LONG).show();
   } else {
       Toast.makeText(context,"SIM UNLOCK FAILED",Toast.LENGTH_LONG).show();
   }

  } catch (Exception e) {
 // 
     e.printStackTrace();
  }

}else{
  Toast.makeText(context,"SIM is not Locked",Toast.LENGTH_LONG).show();
}

现在我想知道已经进行了多少尝试来解锁SIM卡,例如默认的SIM PIN / PUK解锁器告诉“剩下两次尝试”。如果有可能,请告诉我。

1 个答案:

答案 0 :(得分:0)

如果SIM卡解锁失败,只需创建一个从3到0的int

  

int attempts = 3;

     

}其他{

     

Toast.makeText(context," SIM UNLOCK FAILED",Toast.LENGTH_LONG).show();

     

尝试 - ;      }