Android 锁屏小工具

发布于 2024-12-26 04:35:12 字数 173 浏览 1 评论 0原文

一些用户一直在问我为我的应用程序提供 Android 锁屏小部件 - 我相信他们想要一个保留在锁屏上并允许他们与应用程序交互的小部件。

我无法找到任何相关的官方文档 - 我发现的唯一的东西是可以将主屏幕小部件放在锁定屏幕上的应用程序。

有关我在哪里了解有关构建真正的锁屏小部件的更多信息的任何线索吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缱绻入梦 2025-01-02 04:35:12

锁屏交互很困难。 Android 允许使用两个窗口标志(FLAG_SHOW_WHEN_LOCKED 和 FLAG_DISMISS_KEYGUARD)进行基本操作。 FLAG_SHOW_WHEN_LOCKED 的工作方式非常一致,即使启用了安全性,它也会显示在锁定屏幕顶部(安全性不会被绕过,您无法切换到另一个非 FLAG_SHOW_WHEN_LOCKED 窗口)。

如果你只是做一些临时的事情,比如在播放音乐时或类似的事情,你可能基本上不会有什么问题。如果您尝试创建自定义锁定屏幕,那么在所有不同的 Android 平台上都会有很多不寻常的交互。 (“救命!如果不重新启动我的 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

FLAG_SHOW_WHEN_LOCKED

窗口标志:特殊标志,让窗口在屏幕打开时显示
已锁定。

FLAG_DISMISS_KEYGUARD

窗口标志:
设置窗口时将导致键盘保护
仅当它不安全时才被驳回
锁定键盘锁。因为这样的钥匙扣
不需要安全性,它会
如果用户导航,则永远不会重新出现
到另一个窗口(与
FLAG_SHOW_WHEN_LOCKED,这只会
暂时隐藏安全和
非安全的键盘保护装置,但确保它们
当用户移动到时重新出现
另一个不隐藏它们的用户界面)。如果
键盘保护当前处于活动状态并且
是安全的(需要解锁图案)
用户仍然需要
在看到这个窗口之前确认一下,
除非 FLAG_SHOW_WHEN_LOCKED 也有
已设置。
常量值:4194304 (0x00400000)

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)

不必你懂 2025-01-02 04:35:12

我必须为我的项目实现一个锁屏小部件。在这个过程中,我积累了一些资源。

  1. 如果您想将某个应用程序放在锁定屏幕上,请首先将其设为应用程序小部件。您可以使用 AppWidget 类来执行此操作。
  2. 现在,使用 Android API 中的 AppWidgetHost 类来使锁定屏幕成为小部件的主机。我不知道如何执行这部分,但有一些现有的实现,例如 mylockandroid (下面的链接)。

资源

http://code.google.com/p/mylockforandroid/
(注意此代码适用于旧版本的 Android。Android 4.2 及更高版本已内置锁屏小部件支持)

http://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html

I had to implement a lock screen widget for my project. In the process, I accumulated a couple of resources.

  1. If you have an app that you want to put on the lock screen, first make it an appwidget. You can use the AppWidget class to do this.
  2. Now, use the AppWidgetHost class from the Android API to make your lock screen a host for the widgets. I don't know how to do this part, but there are some existing implementations like mylockandroid (links below).

Resources

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://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文