安卓4.3:我如何检查是否用户已锁定启用?

问题描述:

我想我的应用程序不同的行为(而不是存储的东西),如果用户没有锁屏或只刷卡启用。 顶部的答案在这里:检查是否启用锁或不已编辑要说code不再升级后的作品到Android 4.3。

I want my app to behave differently (not store stuff) if the user does not have a lock screen or only swipe enabled. The top answer here: check whether lock was enabled or not has been edited to say the code no longer works after upgrade to Android 4.3.

反正有检测这个在Android 4.3?

Is there anyway to detect this on Android 4.3?

好了,现在看来,这是可能的一些反思。不是最好的解决办法,但至少它的工作原理上我们尝试了设备:

Ok, so it seems it is possible with some reflection. Not the best solution, but at least it works on the devices we tried:

        Class<?> clazz = Class.forName("com.android.internal.widget.LockPatternUtils");
        Constructor<?> constructor = clazz.getConstructor(Context.class);
        constructor.setAccessible(true);
        Object utils = constructor.newInstance(context);
        Method method = clazz.getMethod("isSecure");
        return (Boolean)method.invoke(utils);