Detect changes of “Lock SIM card” in Settings/Security/Set up SIM card lock

耗尽温柔 提交于 2019-11-29 02:46:51
icyerasor

Had to implement a way to finde out if the SimPin is Enabled today. The ITelephony.isSimPinEnabled() always returned false for me, too. Didn't try the other methods you described.

I found a way to get the current setting:

Code:

  Object proxyPhone = PhoneUtil.getProxyPhoneInstance(this);

  Class<?> phone = Class.forName("com.android.internal.telephony.Phone");
  Method getIccCardMethod = phone.getDeclaredMethod("getIccCard");
  Object iccCard = getIccCardMethod.invoke(proxyPhone);
  Class<?> iccCardClass = Class.forName("com.android.internal.telephony.IccCard");

  Method getIccLockEnabled = iccCardClass.getDeclaredMethod("getIccLockEnabled");
  Boolean isIccLockEnabled = (Boolean) getIccLockEnabled.invoke(iccCard);

works for me on Android 2.3(+?), but as mentioned in the other thread you have to run this code as phone-user/as phone-process.

Really kinda disappointed that there is no public api / deviceAdmin-Api for this. Could imagine that companys want to ensure that their employes keep the sim pin enabled (case of theft).

Well, I think I have a easy way to detect if a Sim PIN has to be entered. Best of all it's is avaliable via the SDK. You could run this in a PhoneStateListener...

public static boolean isSimPinRequired(){
    TelephonyManager m = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (m.getSimState() == TelephonyManager.SIM_STATE_PIN_REQUIRED) return true;
    return false;
}//end method
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!