在安卓系统的“设置/位置和安全设置”页面中,有一个名为“SIM卡锁定”的选项。
如果开启了此选项,则需要在启动后输入PIN码。
是否存在编程方法来检测是否需要PIN码?(不是当前SIM状态,而是设置选项值,例如:true/false)
如果开启了此选项,则需要在启动后输入PIN码。
是否存在编程方法来检测是否需要PIN码?(不是当前SIM状态,而是设置选项值,例如:true/false)
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
}
根据评论,这是最终版本:
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;
}
由于 getSimLockEnabled 对我始终返回 false,我不得不找到另一种方法来实现它。