Android - 激活系统键锁(又名锁屏)

发布于 2024-07-16 14:36:51 字数 612 浏览 10 评论 0原文

我必须激活 Android 的系统按键锁(按下关机/挂断按钮时得到的按键锁)。 请参阅此处:

img

我已经浏览过文档,但我发现的所有内容都是 PowerManagerKeyguardManager。 两者似乎都不是解决方案:-(。

那么,每个人都知道如何从 Android 应用程序实现这一点吗?(如果需要特殊权限,那没问题,但更改设备的设置不是解决方案......)

<强>编辑:或者有人知道这绝对不可能吗?顺便说一句,带有发送密钥的解决方案不再起作用(请参阅评论)。

I have to activate android's system key lock (the one you get when you press the power off/hang up button). See here:

img

I already browsed the docs but everything I found was PowerManager and KeyguardManager. Both seem not to be the solution :-(.

So, does everyone know how to achieve that from a android application? (If special permissions are required, that is no problem but changing the device's settings is not a solution...)

EDIT: Or does someone know that this is definitely not possible at all? Btw. craigs solution with sending keys does not work anymore (see comments).

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

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

发布评论

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

评论(5

女中豪杰 2024-07-23 14:36:51

一段时间以来,我一直在寻找完全相同问题的答案。 显然,从 2.0 开始,应用程序级别的设备管理器权限已被删除。 但在 Froyo - 2.2 中,设备策略管理器为我们的开发人员提供了多种管理级别的控制。

http://developer.android.com/guide/topics/admin/device -admin.html

I have been searching for an answer to the exact same question for a while. Apparently, after 2.0 onwards the device manager privileges for the app level were removed. But with Froyo - 2.2 the device policy manager is revealed granting us developers a multitude of administrative level controls.

http://developer.android.com/guide/topics/admin/device-admin.html

樱花细雨 2024-07-23 14:36:51

您正在寻找的是 reenableKeyguard KeyguardManager.KeyguardLock 中的 () 方法我的朋友!

What you're looking for is the reenableKeyguard() method in KeyguardManager.KeyguardLock my friend !

马蹄踏│碎落叶 2024-07-23 14:36:51

看起来屏幕锁定功能是使用

public void goToSleep(long time)

PowerManager.java中的method:方法来执行的。 可以通过这种方式获得对它的引用:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

但是,这需要权限

android.permission.DEVICE_POWER

,该权限是仅系统可用的 2 级权限。

所以看起来这是不可行的。 这仅适用于1.1版本,我不知道1.5版本。

Looks like the screen lock function is performed using the method:

public void goToSleep(long time)

method in PowerManager.java. It's possible to get a reference to it in this fashion:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

However this requires the permission

android.permission.DEVICE_POWER

which is a level 2 permission available to the system only.

So looks like this isn't doable. This is for version 1.1 only, I don't know for 1.5.

青巷忧颜 2024-07-23 14:36:51

这里有一个很好的例子:

http://www.anddev.org/ throwing-simulate_keyrinkles_programatically -t717.html

看起来您可以通过编程方式将任何击键发送到系统。 听起来您正在寻找的密钥代码是 KEYCODE_ENDCALL,但如果这不起作用,这里还有很多其他代码可以尝试:

http://developer.android.com/reference/android/view/KeyEvent.html

我不知道是否有任何API调用导致锁定发生,但这似乎是一个非常可靠的解决方法,直到您找到更好的解决方案。

There's a pretty good example here:

http://www.anddev.org/throwing-simulating_keystrokes_programatically-t717.html

It looks like you can programmatically cause any keystroke to be sent to the system. It sounds like the keycode you're looking for is the KEYCODE_ENDCALL, but if that doesn't work there are plenty of other codes to try here:

http://developer.android.com/reference/android/view/KeyEvent.html

I don't know if there's any API call to cause the lock to occur, but this seems like a pretty sturdy workaround until you find a better solution.

仅一夜美梦 2024-07-23 14:36:51

深入研究 Android 源代码发现 WindowManagerService 似乎有一个公共方法(startAppFreezingScreenLocked)来激活它。 这可能是开始寻找答案的好地方,因为不幸的是,您似乎无法直接获取 WindowManagerService 对象。

Digging through the Android source found WindowManagerService which seems to have a public method (startAppFreezingScreenLocked) for activating this. This may be a good place to start looking for your answer, as unfortunately it doesn't seem as though you can directly get a WindowManagerService object.

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