GDK - keep screen from dimming on a live card

本秂侑毒 提交于 2019-12-18 17:27:56

问题


I have a high frequency live card published and I would like to keep the screen from dimming when the user is looking at the card.

I realize that this is a duplicate question to this one

GDK / APK for Google Glass - Keep screen from dimming

but the answer seems to no longer work. The sample projects don't stay on screen anymore either. I have also tried acquiring the wake lock without success.

Is there a way to keep the screen on?


回答1:


The answer from the question you linked is for Immersion. When using a LiveCard, there is no way to get a wake lock as Glass is taking care of this: this is actually one of the main benefit of a LiveCard, keeping a long running application while Glass takes care of the screen.

If you want the user to be fully immersed in your app while using it, you should go with the Immersion pattern as this will give you full control other the screen.




回答2:


Or you can create your own simple app that changes the screen timeout value.

//change screen timeout to 60 min
    android.provider.Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 600000);

And you also need to specify some permissions:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

Using this I was able to keep my screen awake no matter if I was into an application or visualizing the live cards. At least for my 19.1 version of Glass




回答3:


The only way that worked for me was by acquiring a wakeLock:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , TAG);
wakeLock.acquire(WAKE_LOCK_DURATION_IN_MILLIS);

You also need a permission for that:

<uses-permission android:name="android.permission.WAKE_LOCK" />


来源:https://stackoverflow.com/questions/21403837/gdk-keep-screen-from-dimming-on-a-live-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!