[英]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. 一些用户一直在向我询问我的应用程序的Android锁定屏幕小部件-我相信他们希望保留在锁定屏幕上并允许他们与该应用程序交互的小部件。
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? 关于我在哪里了解有关构建真正的锁屏小部件的更多信息?
Lock screen interaction is difficult. 锁屏互动很难。 Android allows basic operations with two window flags (FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD).
Android允许使用两个窗口标志(FLAG_SHOW_WHEN_LOCKED和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).
FLAG_SHOW_WHEN_LOCKED的工作原理非常一致,即使启用了安全性,它也会显示在锁定屏幕的顶部(不会绕过安全性,您无法切换到另一个非FLAG_SHOW_WHEN_LOCKED窗口)。
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.
如果您尝试创建自定义锁屏,则在所有不同的android平台上都会有很多异常的交互。 ("Help! I can't turn off my alarm without rebooting my HTC phone").
(“帮助!如果不重新启动HTC手机,我将无法关闭闹钟”)。
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 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).
由于安全性不需要这种键盘保护罩,因此如果用户导航到另一个窗口(与FLAG_SHOW_WHEN_LOCKED相反,FLAG_SHOW_WHEN_LOCKED则只会暂时隐藏安全和非安全键盘保护罩,但确保它们在用户移至其他位置时再次出现),它将永远不会重新出现。另一个不会隐藏它们的UI)。 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.
如果键盘锁当前处于活动状态并且是安全的(需要解锁图案),那么除非看到FLAG_SHOW_WHEN_LOCKED也已设置,否则用户仍然需要在看到此窗口之前对其进行确认。 Constant Value: 4194304 (0x00400000)
常数值:4194304(0x00400000)
官方锁屏小部件文档在这里
I had to implement a lock screen widget for my project. 我必须为我的项目实现一个锁屏小部件。 In the process, I accumulated a couple of resources.
在此过程中,我积累了一些资源。
AppWidget
class to do this. AppWidget
类来执行此操作。 AppWidgetHost
class from the Android API to make your lock screen a host for the widgets. AppWidgetHost
类将锁屏设置为小部件的主机 。 I don't know how to do this part, but there are some existing implementations like mylockandroid (links below). http://code.google.com/p/mylockforandroid/ (NB This code is for older versions of Android. Android 4.2 and up has built in lockscreen widget support) http://code.google.com/p/mylockforandroid/ (注意,此代码适用于旧版Android。Android4.2及更高版本已内置锁屏小部件支持)
http://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html http://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.