android“设置/位置和安全设置”页面中有一个“SIM卡锁定”选项。
如果设置了该选项,开机后需要输入PIN码。
是否有任何编程方法来检测是否需要 PIN? (不是当前 sim 状态而是设置选项值 ex:true/false)
最佳答案
您可以使用以下类: 电话管理器 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;
}
关于android - 如何检测解锁 SIM 卡是否需要 PIN 码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5322291/