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.
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello Erel,

No it does not work on my phone (Swipe keyguard, so no password). It works fine on the emulator, version less than Jelly Bean, reason why I asked.

Thanks a lot
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Erel,

Thanks for testing. I did not mentionate this way works of course. I try to unlock via a service (sample project attached) and this works on the emulator.
Could you please let me know what I do wrong.


Main activity
B4X:
Sub Process_Globals


End Sub

Sub Globals
    Dim Button1 As Button
    Dim Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("test")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed AND Not(IsPaused(unlock)) Then
        StopService(unlock)   
    End If   
   
End Sub


Sub SetShowWhenLocked
   Dim r As Reflector
   r.Target = r.GetActivity
   r.Target = r.RunMethod("getWindow")
   r.RunMethod2("addFlags", 6815872, "java.lang.int")
End Sub

Sub Button1_Click ' unlock by activity
    SetShowWhenLocked
End Sub

Sub Button2_Click ' unlock by service
    StartServiceAt(unlock,DateTime.Now+20*1000,True)
End Sub

Service
B4X:
Sub Process_Globals
    Dim T1 As Timer
    Dim WS As PhoneWakeState
   

End Sub
Sub Service_Create
    T1.Initialize("T1",5*1000) ' delay to see the unlock

End Sub

Sub Service_Start (StartingIntent As Intent)
    T1.Enabled=True
    WS.KeepAlive(True)
    If IsPaused(Main) Then
        StartActivity("Main")
    End If
End Sub

Sub Service_Destroy
    WS.ReleaseKeepAlive
End Sub


Sub T1_Tick
    CallSub(Main,"SetShowWhenLocked")
    T1.Enabled=False
End Sub
 

Attachments

  • Unlock.zip
    7.5 KB · Views: 617
Upvote 0

selad

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

Where and when should I call this sub?
 
Upvote 0

Mark Hollingworth

Member
Licensed User
Longtime User
Hi Erel,

I know this is a bit of an old post but I have just used the SetShowWhenLocked code, it seems to work fine when running in debug mode but when I install a release version to my device it throws an error message box with the following text:

An Error has occurred in sub:
java.lang.Exception: Sub was not found
continue?

It looks like the code still works as the activity shows ontop of the lock screen so not sure what is going on, any ideas?

My device is using Android Version 5.0.2 and I am using v5.00 of b4a.
 
Upvote 0

Mark Hollingworth

Member
Licensed User
Longtime User
Hi Erel,

Thanks for the reply, I am now using USB debugging correctly and this is what coming up in the log:

** Service (connectionlistener) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (wifimanagerservice) Create **
** Service (wifimanagerservice) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Service (managerservice) Create **
** Service (managerservice) Start **
Bundle[{admin_intent=Intent { act=android.app.action.ACTION_PASSWORD_FAILED flg=0x10 cmp=co.uk.newappdevelopment.SmartWifiSwitcher/anywheresoftware.b4a.objects.AdminManager$AdminReceiver }}]
failed login
** Activity (main) Pause, UserClosed = false **
** Activity (securityscreen) Create, isFirst = true **
Bring screen to front
Done - Bring screen to front
** Activity (securityscreen) Resume **
java.lang.Exception: Sub was not found.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:193)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:981)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6141)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
java.lang.Exception: Sub was not found.
** Service (connectionlistener) Start **
 
Upvote 0

Mark Hollingworth

Member
Licensed User
Longtime User
ok so after a bit more digging and adding in some more logging I think I have found where the error is coming from (and I probably should of added this info in the first post)

After a password is enter incorrectly my activity is started and it enabled the front camera and takes a picture using the CameraEX library if I remove the code that enables the camera and take the picture I no longer have any errors so it looks like the culprit is in the CameraEx Lib and not the code that displays the activity in front of the lock screen. :oops:

I will create a new thread for this question as its not related, the SetShowWhenLocked code still works fine :)

Thanks for the help
 
Upvote 0
Top