Unlock password locked screen?

MiniDemonic

Member
Licensed User
Longtime 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.
 

MiniDemonic

Member
Licensed User
Longtime 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:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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).

B4X:
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.
 
Upvote 0

salmander

Active Member
Licensed User
Longtime 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).

B4X:
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.
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
 
Upvote 0

salmander

Active Member
Licensed User
Longtime 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.
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?
 
Upvote 0

salmander

Active Member
Licensed User
Longtime 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.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime 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:
Upvote 0

bsnqt

Active Member
Licensed User
Longtime 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).

B4X:
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.

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.
 
Upvote 0

pierpa

Member
Licensed User
Longtime User
the unlocking part works well.

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

B4X:
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
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0
Top