Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some phones, especially older or slow ones, have stripped out some of the Settings ContentObserver functionality in order to preserve resources (like battery). And if I remember correct this was the default behavior in older APIs. A work around is to manually trigger the brightness new setting via a non ui activity like this one:</p> <pre><code>public class act_brightnesshelper extends Activity { //----- Private Static Members ----- private static final String TAG = "act_brightnesshelper"; //----- Private Static Members END ----- //----- Private Members ----- private int brightnessLevel; //----- Private Members END ----- //----- Activity Overrides ----- @Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); brightnessLevel = this.getIntent().getExtras().getInt("brightnessLevel"); } @Override public void onAttachedToWindow() { Log.d(TAG, "onAttachedToWindow brightnessLevel = " + brightnessLevel); super.onAttachedToWindow(); WindowManager.LayoutParams lp = getWindow().getAttributes(); try { lp.screenBrightness = brightnessLevel / 255f; getWindow().setAttributes(lp); } catch(Exception ex) { //Do Nothing... } //Finish the Activity after 500ms... Thread WaitThread = new Thread(){ @Override public void run() { try {Thread.sleep(500);} catch (InterruptedException e) {} finish(); } }; WaitThread.start(); } //----- Activity Overrides END----- } </code></pre> <p>and call it after you change the brightness setting by passing the required brightness level in the intent extra like this:</p> <pre><code>Settings.System.putInt(&lt;cnt resolver&gt;, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); Settings.System.putInt(&lt;cnt resolver&gt;, Settings.System.SCREEN_BRIGHTNESS, &lt;your level&gt;); Intent iBriHelper = new Intent(cx, act_brightnesshelper.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); iBriHelper.putExtra("brightnessLevel", &lt;your level&gt;); context.startActivity(iBriHelper); </code></pre> <p>for this to be right you have to declare the activity in the manifest like this:</p> <pre><code>&lt;activity android:name=".act_brightnesshelper" android:theme="@style/Theme.Transparent" android:configChanges="orientation" android:noHistory="true" android:excludeFromRecents="true"&gt; &lt;/activity&gt; </code></pre> <p>If you are changing the brightness inside an activity then you can do this directly in it. The code I provide is for changing the brightness outside the context of an activity i.e. an app-widget.</p> <p><strong>EDIT Based on OP comments</strong></p> <p>Let's take a look at BrightnessController.java from android source code <a href="https://github.com/android/platform_frameworks_base/blob/master/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java" rel="nofollow">here</a> as you can see in line 164 is the function which called whenever the user changes the brightness slider in the system settings ui. In line 174 the brightness setting is updated via the Settings.system class as you and I do in our code. BUT before that in line 170 there is a call to function setBrightness (declared in line 193). </p> <p>setBrightness set the brightness level via a call to setTemporaryScreenBrightnessSettingOverride which is a call to IPowerManager.Stub.asInterface(ServiceManager.getService("power")). Actually android itself is doing what I proposed. It sets the brightness level via a system call which it seems that it is equivalent to:</p> <pre><code>lp.screenBrightness = brightnessLevel / 255f; getWindow().setAttributes(lp); </code></pre> <p>called in an activity and then it sets the actually setting in the database. So actually what I propose isn't a work around but it is how the system do it. I don't think that there is an implementation error in the device you are mentioning but rather that it has to do with the hardware itself and since android doesn't communicate with the hardware directly (<a href="http://www.android-app-market.com/android-architecture.html" rel="nofollow">see here</a>) it may be on how the hardware or the driver is designed in this phone.</p> <p>Hope this helps...</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