开发者

Cant use PowerManager's goToSleep APi in android

开发者 https://www.devze.com 2023-03-10 11:12 出处:网络
Hiifelas i was makingan app and i need to invoke the phonegoing into screen-saver 开发者_开发知识库mode as i get a triger...

Hii felas i was making an app and i need to invoke the phone going into screen-saver 开发者_开发知识库mode as i get a triger... I looked around and found out that PowerManager.java does provide such an API "goToSleep"

API description here.

my problem now is that I need a special permission to make this work namely

"android.Manifest.permission.DEVICE_POWER" this permission being a level 2 permission just declaring it in manifest does not provide me with the permission

so now i have to run the app in system thread (have verified it works if i do so ) to get this permission successfully

can anybody provide me any tips or any other way around as how i can make this work without rooting my app (is there some other way to trigger the same behavior


Under a certain brightnes value, the screen goes off so this should work:

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
lp.screenBrightness = 0;
getWindow().setAttributes(lp);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号