Requirements: Open and close the screen in the program (through events, etc.)
Idea: In general, turning off the screen does not really turn off the screen, but the brightness of the screen is minimized. In general, Android devices have a limit on the minimum brightness that can be adjusted on the screen. If your device really allows the screen to be completely turned off, you can only consider the features of the device, and when you write a program, consider most devices.
Realize:
Enable the On-screen function private void Turnonscreen () {Windowmanager.layoutparams params = GetWindow (). GetAttributes ();p arams.flags | = Windowmanager.layoutparams.flag_keep_screen_on;params.screenbrightness = 1;getwindow (). SetAttributes (params);} Turn off the on-screen function private void Turnoffscreen () {Windowmanager.layoutparams params = GetWindow (). GetAttributes ();p arams.flags |= windowmanager.layoutparams.flag_keep_screen_on;params.screenbrightness = 0.005f;getwindow (). SetAttributes ( params);}
Android closes and opens the screen in the program