Unlock password locked screen?

Discussion in 'Android Questions' started by MiniDemonic, Feb 10, 2012.

  1. MiniDemonic

    MiniDemonic Member Licensed User

    Is it possible to unlock or disable a password screenlock?

    For example if some conditions in my app is true then the screenlock will not appear when the user wakes his phone.
    But if the conditions are false the screenlock will appear and he will have to type his password.
     
    Mauro likes this.
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    NJDude likes this.
  3. MiniDemonic

    MiniDemonic Member Licensed User

    Thanks, will look into that.

    Edit:
    Don't understand how to use this in the Reflection library, I'm a beginner after all.
    Any help would be appreciated.

    What I'm looking for exactly is.

    When the conditions are met, the slide to unlock screenlock appears.
    When the conditions are not met, the type password to unlock screenlock appears.

    Don't know if I can explain any better. :/

    An app that does almost what I'm trying to do is "Unlock by WiFi".
     
    Last edited: Feb 10, 2012
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible to completely unlock a password locked screen (this will break the whole idea of a password locked screen).

    You can use this code to dismiss the lock if there is no password and also show the current activity before the lock screen (if there is a password).

    Code:
    Sub SetShowWhenLocked
       
    Dim r As Reflector
       r.Target = r.GetActivity
       r.Target = r.RunMethod(
    "getWindow")
       r.RunMethod2(
    "addFlags"6815872"java.lang.int")
    End Sub
    It will also keep the screen on while the activity is visible.
    You can change addFlags to clearFlags to remove this behavior.
     
  5. MiniDemonic

    MiniDemonic Member Licensed User

    Thanks, it's not exactly what I am looking for, but this will do.

    Great support as always Erel!
     
  6. salmander

    salmander Active Member Licensed User

    Hi Erel,

    I couldn't find on android developers portal about the code "6815872", which you have mentioned in your post. What does it do?
    However,
    FLAG_DISMISS_KEYGUARD = 4194304
    FLAG_SHOW_WHEN_LOCKED = 524288
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    This is a combination of: FLAG_TURN_SCREEN_ON, FLAG_DISMISS_KEYGUARD, FLAG_SHOW_WHEN_LOCKED and FLAG_KEEP_SCREEN_ON.

    This is the same set of flags that the native alarm clock uses.
     
  8. salmander

    salmander Active Member Licensed User

    Thanks Erel. I understand now. While searching for ScreenLock apps, I came across Device Administrator functionality in Android. Which is here

    How can i achieve this in basic4android please?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    A new library is required for this API. Note however that this API is only for admin apps. Not standard consumer apps.
     
  10. salmander

    salmander Active Member Licensed User

    okay.... :sign0148: So can you look into that please? Or shall I open a new Thread? There are a lot of "Basic4ppc Experts", maybe someone can bless us with this library. :sign0188:

    Thanks Erel.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread in the wishlist forum.
     
  12. salmander

    salmander Active Member Licensed User

    Cheers Erel. I will do that.
     
  13. salmander

    salmander Active Member Licensed User

  14. NeoTechni

    NeoTechni Well-Known Member Licensed User

    How do I use this API?

    I put it in activity_create and I get

    main_setshowwhenlocked (java line: 3586)
    java.lang.NoSuchFieldError: anywheresoftware.b4a.BA.activityBA
    at anywheresoftware.b4a.agraham.reflection.Reflection.GetActivity(Reflection.java:638)
    at com.omnicorp.lcarui.dialer.main._setshowwhenlocked(main.java:3586)
    at com.omnicorp.lcarui.dialer.main._activity_create(main.java:566)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
    at com.omnicorp.lcarui.dialer.main.afterFirstLayout(main.java:84)
    at com.omnicorp.lcarui.dialer.main.access$100(main.java:16)
    at com.omnicorp.lcarui.dialer.main$WaitForLayout.run(main.java:72)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3701)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
    at dalvik.system.NativeStart.main(Native Method)

    EDIT: I searched other topics, and another said the reflection library was out of date. I updated from 1.90 to 2.20 and it worked.
    (A good endorsement for an auto-updater for the libraries)
     
    Last edited: Nov 23, 2012
  15. bsnqt

    bsnqt Active Member Licensed User

    Dear Erel,

    Can you please advise me more about how to "change addFlags to clearFlags to remove this behavior". I call SetShowWhenLocked as you mentioned above, and now I want to re-enable the lock status (i.e. my purpose is not to "physically" lock the screen like the Device Administration Library does, but just only re-enable it - i.e. to bring it into the status that was before I call SetShowWhenLocked). I tried to search around but found no Flag value that let me re-enable the Lock status.

    Thank you.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Try this:
    Code:
    r.RunMethod2("clearFlags"0"java.lang.int")
     
  17. bsnqt

    bsnqt Active Member Licensed User

    Thank you very much Erel.
     
  18. pierpa

    pierpa Member Licensed User

    the unlocking part works well.

    after the "unlocking" layout i want to change layout and let the screen go off after timeout.

    Code:
    Dim r As Reflector
    Activity.RemoveAllViews
    Activity.LoadLayout("checkout")
    r.Target = r.GetActivity
    r.Target = r.RunMethod(
    "getWindow")
    r.RunMethod2(
    "clearFlags"0"java.lang.int")
    but screen remains on forever
     
  19. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Hello,

    Does this method still work with Jelly Bean ? I can't manage it to unlock my own phone to allow LocationManager to grap its data.

    Thanks
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    It should work if a password is not required to unlock the screen.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice