Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lock Screen Widget

A few users have been asking me Android lock screen widgets for my app - I believe they want a widget that stays on their lock screens and allows them to interact with the app.

I haven't been able to find any official documentation for this - the only thing I found was apps that will take home screen widgets and put them on the lock screen for you.

Any clues on where I learn more about building true lock-screen widgets?

like image 879
psychotik Avatar asked Nov 07 '10 00:11

psychotik


People also ask

Can you add widget to lock screen Android?

If your device is running Android 4.2 or later (until 5.0), you can add a widget to your lock screen using the following steps: From your lock screen, swipe to reach the leftmost lock screen page. Tap on the + icon to add a new widget.

Does Samsung have lock screen widget?

How to enable lock screen widgets in One UI. First, open the Settings app on your phone. Then, go to “Lock screen” and tap “Widgets.” This menu will show a list of available lock screen widgets, including Music, Today's schedule, Next alarm, Weather, Bixby Routines, Voice Recorder, and Digital Wellbeing.


2 Answers

Lock screen interaction is difficult. Android allows basic operations with two window flags (FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD). FLAG_SHOW_WHEN_LOCKED works pretty consistently in that it will show on top of the lock screen even when security is enabled (the security isn't bypassed, you can't switch to another non-FLAG_SHOW_WHEN_LOCKED window).

If you're just doing something temporary, like while music is playing or similar, you'll probably mostly be okay. If you're trying to create a custom lock screen then there's a lot of unusual interactions on all the different android platforms. ("Help! I can't turn off my alarm without rebooting my HTC phone").

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html

FLAG_SHOW_WHEN_LOCKED 

Window flag: special flag to let windows be shown when the screen is locked.

FLAG_DISMISS_KEYGUARD 

Window flag: when set the window will cause the keyguard to be dismissed, only if it is not a secure lock keyguard. Because such a keyguard is not needed for security, it will never re-appear if the user navigates to another window (in contrast to FLAG_SHOW_WHEN_LOCKED, which will only temporarily hide both secure and non-secure keyguards but ensure they reappear when the user moves to another UI that doesn't hide them). If the keyguard is currently active and is secure (requires an unlock pattern) than the user will still need to confirm it before seeing this window, unless FLAG_SHOW_WHEN_LOCKED has also been set. Constant Value: 4194304 (0x00400000)

like image 87
Kevin TeslaCoil Avatar answered Oct 02 '22 18:10

Kevin TeslaCoil


Official Lock screen widget document is here

like image 28
Bao Le Avatar answered Oct 02 '22 20:10

Bao Le