Android Setting System brightness

Source: Internet
Author: User

Modify system brightness in Android player

/** * Player Activity */public class Playeractivity extends Activity {/** * system automatically adjusts brightness */private Boolean Isautobrig    Htness = false; /** * System Brightness Change value */private static final int system_brightness_change_values = 25;/** * Maximum system volume value */private static final int MAX _system_brightness_values = 255; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); /** * Open the Player interface to determine if the system is set to auto brightness * Set the system brightness if the system brightness set automatic brightness, you need to turn off the auto brightness */isautobrightness = deviceutil.isautobrightness (This) ; if (isautobrightness) {deviceutil.stopautobrightness (this);}}    @Overrideprotected void Onresume () {/* * Player request screen is required to be written in the Onresume method, if written in the OnCreate () method, * When the user presses home after playback, the screen always fails */ Deviceutil.requirescreenon (this);/** * Resolve User Press home back to player brightness mode for auto brightness re-method: (Auto brightness on playeractivity--> Press home--( Enter system settings at this time * system brightness is non-auto brightness) modified to auto brightness--back to the player) */isautobrightness = deviceutil.isautobrightness (this); isautobrightness) {deviceutil.stopautobrightness (this);}} @Overridepublic Boolean OnkEydown (int keycode, keyevent event) {//TODO auto-generated method Stubint currsettingbrighiness = Deviceutil.getsystemsc Reenbrightness (this), switch (keycode) {case keyevent.keycode_dpad_up://system brightness plus addsystembrighiness ( currsettingbrighiness) break;case keyevent.keycode_dpad_down://System Brightness reduction minussystembrighiness (currSettingBrighiness ); break;default:break;} Return Super.onkeydown (KeyCode, event);} /** * System Brightness plus * * @param currsettingbrighiness * System current brightness */private void addsystembrighiness (int Currsettingbrighi Ness) {if (Currsettingbrighiness < max_system_brightness_values&& (currsettingbrighiness + SYSTEM_ Brightness_change_values) < max_system_brightness_values) {setsystembrighiness = currsettingbrighiness+ SYSTEM_ Brightness_change_values;deviceutil.setsystemscreenbrightness (this, setsystembrighiness);}} /** * System Brightness minus * * @param currsettingbrighiness * System current brightness */public void minussystembrighiness (int currsettingbrigh iness) {if (currsettingbrighiness >= system_brightness_change_values) {setsystembrighiness = Currsettingbrighiness-system_brightness_change_values;d Eviceutil.setsystemscreenbrightness (this, setsystembrighiness);}}}

/** * Deviceutil Tool class */public class Deviceutil {/** * get system brightness * Take value between (0--255) */public static int GE        Tsystemscreenbrightness (context context) {int values = 0;        try {values = Settings.System.getInt (Context.getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS);        } catch (Settingnotfoundexception e) {//TODO auto-generated catch block E.printstacktrace ();    } return values; }/** * Set system brightness * @param systembrightness The luminance value returned is an integer value between 0-255 */public static Boolean SETSYSTEMSCR Eenbrightness (context context, int systembrightness) {return Settings.System.putInt (Context.getcontentresolver (), S Ettings.    system.screen_brightness,systembrightness); }/** * system automatically adjusts brightness * return true is auto adjust brightness return false not automatically adjusts brightness */public static Boolean isautobrightness (Activity activit Y) {int autobrightness = settings.system.screen_brightness_mode_automatic;try {autobrightness = Settings.System. GetInt (Activity.getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS_MODE);} catch (Settingnotfoundexception e) {e.printstacktrace ();} if (autobrightness = = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {return true;} else {return false;}} /** * Turn off system auto Adjust brightness */public static void stopautobrightness (activity activity) {Settings.System.putInt ( Activity.getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_ MANUAL);} /** * Turn on system auto Adjust brightness */public static void startautobrightness (activity activity) {Settings.System.putInt ( Activity.getcontentresolver (), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_ AUTOMATIC);} /** * Request Screen Solid * @param activity */public static void Requirescreenon (activity activity) {Activity.getwindow (). SetFlags ( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);} /** * Cancel Solid screen * @param activity */public static void Releasescreenon (activity activity) {Activity.getWindow (). Clearflags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);}} 

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Setting System brightness

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.