How can I brighten the screen when opening an Activity in my Glass GDK immersion application?

蹲街弑〆低调 提交于 2019-12-05 05:51:35

I was able to find a solution by acquiring a SCREEN_BRIGHT_WAKE_LOCK with the ACQUIRE_CAUSES_WAKEUP flag in onResume. For example:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "My Tag");
wl.acquire();
//..screen will stay on during this section..
wl.release();

Try to put the code before the call to setContentView in onCreate (the brightness level won't update otherwise), something like:

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);

  WindowManager.LayoutParams lp = getWindow().getAttributes();
  lp.screenBrightness = 1.0f;
  getWindow().setAttributes(lp);
  // example
  setContentView(R.layout.main);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!