Android Question how do I launch an activity over the lock screen?

RichyK68

Active Member
Licensed User
Longtime User
Hi,

I'm need to launch an activity from a foreground service and, if the lock screen is active (even a password-protected one) I need the activity to show, but it's proving very problematic. Here is the code I'm using:

Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")

Dim flag As Int = Bit.OR(Bit.OR(Bit.OR(MyFunctions.FLAG_SHOW_WHEN_LOCKED, MyFunctions.FLAG_TURN_SCREEN_ON), MyFunctions.FLAG_KEEP_SCREEN_ON), MyFunctions.FLAG_FULLSCREEN)
flag = Bit.OR(flag, MyFunctions.FLAG_ACTIVITY_SINGLE_TOP)
flag = Bit.OR(flag, MyFunctions.FLAG_DISMISS_KEYGUARD)
r.RunMethod2("addFlags", flag, "java.lang.int")

I am using this code in the Activity_Create method, but it has no effect. Any ideas?

Cheers,

Richard
 

RichyK68

Active Member
Licensed User
Longtime User
Yes, it's the same idea, it works 50% of the time in debug mode and almost not at all in release mode though (on my S4).
 
Upvote 0

RichyK68

Active Member
Licensed User
Longtime User
It's to do with VR. My activity that is launched uses VR, and if I do a VR.Listen in the Activity_Resume the VR fails to start up, and the activity fails to show. If I take out the VR.Listen, the activity will appear over the lock screen about 90% of the time (I'd prefer 100% though). I've added a timer that is started in the Activity_Create that, after 1.5 seconds, does the VR.Listen. This gives the activity time to appear over the lock screen before starting VR. It works a lot of the time, still not 100%, and it slows down the interface (having to wait for the VR prompt to appear) but it's better than it was. I may have to look into speech recognition using a different method.

ps is there a property I can check (like Visible in .Net) to see if the activity has actually appeared yet? I could check this flag in the timer and make the timer interval shorter, and therefore (hopefully) get the VR to appear faster.
 
Upvote 0

RichyK68

Active Member
Licensed User
Longtime User
Sadly, the VR attempts to pop up, makes that bling noise but then disappears and hides behind the lock screen.
I find starting a timer in the Activity_Resume and waiting for several seconds, then launching the VR, works most of the time. It's a workaround, not necessarily a good one.
 
Upvote 0
Top