本文介绍了保持屏幕上,哪种方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现两种方法在保持在屏幕上:

I have found two ways on keeping the screen on:

第一个是简单的:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

第二人使用一个wakelock并要求一个额外的许可:

Second one is using a wakelock and requiring an extra permission:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

有此之间有任何真正的区别两种方法分开,第二个是更复杂实现和要求一个额外的许可?将最终的结果总是一样的吗?

Is there any real difference between this two methods apart from the second one being more complicated to implement and requiring an extra permission? Will the end result be always the same?

推荐答案

您应该看到的的谷歌IO presentation,滑动16

You should see Coding for (Battery) Life Google IO presentation, slide 16

如果你不想,那么:你可以做第一个在XML中的任何一个布局元素,它是建议之一来使用(不知道,虽然把它应用到了窗口,可能是因为糟糕的wakelock,说不上来)。

If you don't want to, then: You could do the first one in the XML for any layout element and it is the suggested one to use (don't know about applying it to the window though, might be as bad as the wakelock, dunno).

XML:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:keepScreenOn="true">

窗口标志:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

这篇关于保持屏幕上,哪种方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:18