我可以阻止手机在网页上睡觉吗? [英] Can I prevent phone from sleep on a webpage

查看:116
本文介绍了我可以阻止手机在网页上睡觉吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序中,我可以使用 http://developer.android.com /reference/android/os/PowerManager.WakeLock.html
但有没有办法让网页运行并防止入睡?
如果它至少在android上运行会很好。

In app I can use http://developer.android.com/reference/android/os/PowerManager.WakeLock.html but is there a way to keep webpage running and prevent from going to sleep? It would be nice if it runs at least on android.

推荐答案

在应用程序中有两种方法你可以做到,但我想你的意思只是在移动网页上,在任何浏览器中通过Android查看。使用普通的HTML / Javascript /等等,我真的非常怀疑它。

In an app there are a couple of ways you can do it, but I guess you mean just in a mobile web page, viewed in any browser via Android. With normal HTML/Javascript/etc., I really, really doubt it.

实际上可能可以使用Flash(在启用闪存时)但是,至少在特定情况下,启用了插件的手机)。我这样说是因为,在没有WAKE_LOCK权限的测试应用中,加载此swf文件进入WebView会在某些设备上导致以下异常:

It actually may be possible using Flash (on flash-enabled phones with plugins enabled), though, at least in specific circumstances. I say this because, in a test app without the WAKE_LOCK permission, loading this swf file into a WebView caused the following exception on some devices:


java.lang.SecurityException:
user #### #或当前进程有
android.permission.WAKE_LOCK

java.lang.SecurityException: Neither user ##### nor current process has android.permission.WAKE_LOCK

然而,即使这确实有效,也会冒风险崩溃的应用程序或浏览器没有WAKE_LOCK权限。这可能是由于Adobe Flash Player插件中的代码错误而非任何有意的功能。

Even if this did work, however, it would run the risk of crashing apps or browsers that did not have the WAKE_LOCK permission. It may be possible due to bad code in the Adobe Flash Player plugin, rather than any intentional functionality.

这篇关于我可以阻止手机在网页上睡觉吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆