如何检测解锁 sim 是否需要 PIN 码?

2023-12-12

Android“设置/位置和安全设置”页面中有一个“SIM 卡锁定”选项。

如果设置了该选项,则开机后需要输入PIN码。

是否有任何编程方法来检测是否需要 PIN 码? (不是当前的 sim 状态,而是设置选项值,例如: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;
       }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何检测解锁 sim 是否需要 PIN 码? 的相关文章