When adjusting the brightness of the screen, set the current activity brightness, and then save the brightness of the system.
1 onCreate () Check the system brightness and set the Seekbar:
private void Screenbrightness_check () {///First turn off the system's brightness auto-adjust try {if (and Roid.provider.Settings.System.getInt (Getcontentresolver (), android.provider.Settings.System.SCREEN_BRIGHTNESS_ MODE) = = = Android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {Android . Provider. Settings.System.putInt (Getcontentresolver (), Android.provider.Settings.System.SCREEN_BRIGHTNESS_MO
DE, Android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
The catch (Settingnotfoundexception e) {//TODO auto-generated catch block
E.printstacktrace (); //Gets the current brightness, and returns 255 intscreenbrightness= (int) (Android.provider.Settings.System.getInt Getcontentreso
Lver (), Android.provider.Settings.System.SCREEN_BRIGHTNESS, 255)); Text, enterThe degree bar shows mseekbar_light.setprogress (intscreenbrightness);
Mtextview_light.settext ("" +intscreenbrightness*100/255); }
2 Drag Seekbar to set the current activity brightness and save As System brightness:
Screen brightness private void setscreenbritness (int brightness) {//Do not allow screen full dark if (brightness<=1)
{Brightness=1;
//Set screen brightness for current activity windowmanager.layoutparams LP = This.getwindow (). GetAttributes ();
0 to 1, adjust brightness dark to full bright lp.screenbrightness = float.valueof (brightness/255f);
This.getwindow (). SetAttributes (LP); Save As System brightness Method 1 Android.provider.Settings.System.putInt (Getcontentresolver (), ANDROID.PROVIDER.S Ettings.
system.screen_brightness, brightness);
Save As System brightness Method 2//URI URI = Android.provider.Settings.System.getUriFor ("screen_brightness");
Android.provider.Settings.System.putInt (Getcontentresolver (), "screen_brightness", brightness);
Resolver.registercontentobserver (URI, True, Mycontentobserver);
Getcontentresolver (). Notifychange (URI, NULL); Change LightThe degree text displays Mtextview_light.settext ("" +brightness*100/255); }