android“设置/位置和安全设置”页面中有一个“SIM卡锁定”选项。
如果设置了该选项,则需要在开机后输入 PIN 码。
是否有任何编程方法来检测是否需要 PIN?(不是当前的 sim 状态,而是设置选项值 ex:true/false)
您可以使用以下类: TelephonyManager http://developer.android.com/reference/android/telephony/TelephonyManager.html
您不直接实例化此类;相反,您通过 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
}
在评论之后,这是最终版本:
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,我必须找到另一种方法来做到这一点。