turn the screen on/off in Android with a shake

青春壹個敷衍的年華 提交于 2019-12-06 07:41:53

I agree with icyerasor's guess, however -- If the guess is correct and the phone is going to sleep you will have to acquire a PARTIAL_WAKE_LOCK to keep the CPU awake before you set the brightness to 0.0

I would test this before answering but I don't have access to an Android device at this moment.

Just a guess: Setting it to brighnes 0.0 might also put the phone in sleep mode?

When you want to turn it on again programmatically, try acquiring a ACQUIRE_CAUSES_WAKEUP Wakelock:

PowerManager pm = (PowerManager)mContext.getSystemService(
                                          Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(
                                      PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                                      | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                                      TAG);
wl.acquire(1000);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!