简体   繁体   中英

Android set or reset SIM card PIN code programmatically

I have implemented below given to unlock my app (this code works for only systems apps so I have done my app as system app )

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();
}

It works fine for me, but now I need to implement setting or resetting SIM PIN programmatically, let me know if it is possible or not. if possible than how can I implement that?

String ussdCode = "**04*"+oldPin+"*"+newPin+"*"+newPin+"#";
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM