/*** Get the current screen brightness mode * screen_brightness_mode_automatic=1 to automatically adjust the screen brightness * screen_brightness_mode_manual=0 To manually adjust the screen brightness */ Private intGetscreenmode () {intScreenmode = 0; Try{Screenmode=Settings.System.getInt (Getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS_MODE); } Catch(Exception localexception) {}returnScreenmode; } /*** Get current screen brightness value 0--255*/ Private intgetscreenbrightness () {intScreenbrightness = 255; Try{screenbrightness=Settings.System.getInt (Getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS); } Catch(Exception localexception) {}returnscreenbrightness; } /*** Set the current screen brightness mode * screen_brightness_mode_automatic=1 to automatically adjust the screen brightness * screen_brightness_mode_manual=0 To manually adjust the screen brightness */ Private voidSetscreenmode (intparamint) { Try{Settings.System.putInt (Getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS_MODE, paramint); } Catch(Exception localexception) {localexception.printstacktrace (); } } /*** Set the current screen brightness value 0--255*/ Private voidSavescreenbrightness (intparamint) { Try{Settings.System.putInt (Getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS, paramint); } Catch(Exception localexception) {localexception.printstacktrace (); } } /*** Save the current screen brightness value and make it effective*/ Private voidSetscreenbrightness (intparamint) {Window Localwindow=GetWindow (); Windowmanager.layoutparams Locallayoutparams=localwindow.getattributes (); floatf = paramint/255.0f; Locallayoutparams.screenbrightness=F; Localwindow.setattributes (Locallayoutparams); }
Android Settings System screen brightness