how to detect if PIN code is required to unlock sim?

喜夏-厌秋 提交于 2019-11-30 07:41:29

You can use the following class: TelephonyManager http://developer.android.com/reference/android/telephony/TelephonyManager.html

You do not instantiate this class directly; instead, you retrieve a reference to an instance through Context.getSystemService(Context.TELEPHONY_SERVICE)

TelephonyManager manager = (TelephonyManager) Context.getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
         //PIN/PUK is required
}

Following the comments, this is the final version:

TelephonyManager tm = 
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
       Class clazz = Class.forName(tm.getClass().getName());
       Method m = clazz.getDeclaredMethod("getITelephony");
       m.setAccessible(true);
       ITelephony it = (ITelephony) m.invoke(tm);
       if(it.isSimPinEnabled())
       {
                //This should work;
       }
icyerasor

As getSimLockEnabled always returns false for me, i had to find another way to do it.

See https://stackoverflow.com/a/12748638/314089 for the answer.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!