Pregunta

I want to use an android internal class, com.android.internal.widget.LockPatternUtils .

I searched for examples and I got this:

LockPatternUtils lpu = new LockPatternUtils(this.getContentResolver());

However, i cant import, autimport does not appear and manually doing

import com.android.internal.widget.LockPatternUtils 

doesnt work.

How is this handled? I think there was something about creating an interface but not sure about it

EDIT: I got this:

  boolean patternLocked = android.provider.Settings.System.getInt(
     getContentResolver(),Settings.System.LOCK_PATTERN_ENABLED, 0)==1;

That works for the pattern lock, but i cant know about the pin or password lock

¿Fue útil?

Solución 2

How is this handled?

Those classes are only available as part of full firmware builds, not from Android SDK apps.

Otros consejos

Use reflection to access the internal Android method getActivePasswordQuality (line 350 of LockPatternUtils.java) and compare the int it returns to the int for any of the DevicePolicyManager Constants:

protected boolean isSecure() {

    String LOCK_PATTERN_UTILS = "com.android.internal.widget.LockPatternUtils";

    try {
        Class<?> lockPatternUtilsClass = Class.forName(LOCK_PATTERN_UTILS);
        Object lockPatternUtils = lockPatternUtilsClass.getConstructor(Context.class).newInstance(this);
        Method method = lockPatternUtilsClass.getMethod("getActivePasswordQuality");
        int lockProtectionLevel = Integer.valueOf(String.valueOf(method.invoke(lockPatternUtils)));

        // Then check if lockProtectionLevel == DevicePolicyManager.TheConstantForWhicheverLevelOfProtectionYouWantToEnforce, and return true if the check passes, false if it fails
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }

    return false;
}

You can not use Android internal classes, they do not come with the public SDK.

You can build your own SDK exposing them more or less as they do here How do I build the Android SDK with hidden and internal APIs available?

This is not recommended because you will have no guarantees.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top