如何prevent Android设备的活动的执行过程中关闭屏幕? [英] How to prevent the screen of an android device to turn off during the execution of an Activity?

查看:81
本文介绍了如何prevent Android设备的活动的执行过程中关闭屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,通常需要一些时间来观看屏幕,不与其进行交互。

I have an Activity that usually needs some time to watch the screen without interacting with it.

问题是,屏幕将自动关闭,就像Almos酒店的其他应用程序。 我想prevent的自动关闭我的活动,像海豚高清呢(如果你在设置菜单中进行配置)。

The problem is that the screen turns off, just like with almos any other app. I want to prevent that automatic turn off for my Activity, like Dolphin HD does (if you configure it from the settings menu).

我想让用户关闭屏幕pressing平时块按钮,但prevent设备的自动闭塞,而​​在我的活动

I want to let the user to turn off the screen pressing the usual block button, but prevent the automatic block of the device while in my Activity.

我怎样才能做到这一点?

How can I achieve this?

感谢名单。

推荐答案

添加安卓keepScreenOn =真正的来为这次活动你的布局XML资源的一些小部件。只要该部件是在屏幕上可见,屏幕也不会自动关闭。

Add android:keepScreenOn="true" to some widget in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.

编辑:

A WakeLock 建议的那样,其他的答案,在技术上将工作。但你必须手动释放 WakeLock (如果你陷入困境,高达,屏幕上会停留在很长一段时间)。而且,由于你的可以的搞砸了,你需要的 WAKE_LOCK 许可。使用 keepScreenOn 避免这一切。

A WakeLock, as suggested by other answers, technically will work. But then you have to manually release the WakeLock (if you mess that up, the screen will stay on a long time). And, since you could mess it up, you need the WAKE_LOCK permission. Using keepScreenOn avoids all of that.

这篇关于如何prevent Android设备的活动的执行过程中关闭屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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