Android : Android set or reset SIM card PIN code programmatically

on Thursday, September 11, 2014


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?


0 comments:

Post a Comment