GDK / APK for Google Glass - Keep screen from dimming

蹲街弑〆低调 提交于 2019-12-18 12:10:01

问题


What part of the code in the four sample APK projects listed here for Google Glass prevents the screen from dimming?

When I write my own APK and sideload it, after ten seconds with no tapping, the screen dims but does not turn off.

What manifest change or code change can I use to prevent the screen from dimming.

Thanks! Should there be a Google-Glass-GDK tag? If so add it please.


回答1:


There are a couple easy ways you can do this without requesting a wake lock:

  • Add the android:keepScreenOn="true" attribute to the root element of your layout.

  • Or, do the following in your onCreate method:

  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);



回答2:


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/18502143/gdk-apk-for-google-glass-keep-screen-from-dimming

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