Programmatically switching off Android phone

后端 未结 6 1765
清歌不尽
清歌不尽 2020-11-22 13:02

Can we switch off an Android phone programmatically?

I am using following snippet but it didn\'t work for me.

KeyguardManager keyguardManager = (Keyg         


        
6条回答
  •  旧巷少年郎
    2020-11-22 13:40

    Actually, the above responses are not completely accurate, in my experience. I was experimenting with ways to dim the screen and found that the following:

    Window w = getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.screenBrightness =.005f;
    w.setAttributes (lp);
    

    will actually turn my Samsung Galaxy Tab off if, instead of 0.005, I use a screen brightness value of 0.

    I suspect this is bug somewhere, but I don't have sufficient hardware to test the code on other Android models. Hence, I can't really tell you what will happen on your phone. I can tell you that my code shuts of my phone even completely unsigned.

提交回复
热议问题