Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use following :</p> <pre><code>//Variable to store brightness value private int brightness; //Content resolver used as a handle to the system's settings private ContentResolver cResolver; //Window object, that will store a reference to the current window private Window window; </code></pre> <p>In your onCreate write:</p> <pre><code>//Get the content resolver cResolver = getContentResolver(); //Get the current window window = getWindow(); try { // To handle the auto Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); //Get the current system brightness brightness = System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS); } catch (SettingNotFoundException e) { //Throw an error case it couldn't be retrieved Log.e("Error", "Cannot access system brightness"); e.printStackTrace(); } </code></pre> <p>Write the code to monitor the change in brightness.</p> <p>then you can set the updated brightness as follows:</p> <pre><code> //Set the system brightness using the brightness variable value System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness); //Get the current window attributes LayoutParams layoutpars = window.getAttributes(); //Set the brightness of this window layoutpars.screenBrightness = brightness / (float)255; //Apply attribute changes to this window window.setAttributes(layoutpars); </code></pre> <p>Permission in manifest:</p> <pre><code>&lt;uses-permission android:name="android.permission.WRITE_SETTINGS"&gt;&lt;/uses-permission&gt; </code></pre> <p>For API > 23, you need to request the permission through Settings Activity, described here: <a href="https://stackoverflow.com/questions/32083410/cant-get-write-settings-permission">Can&#39;t get WRITE_SETTINGS permission</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload