I would like to modify, how fast the screen brightness is changed by Android, if Automatic brightness is enabled in the Android Settings.

The issue is that it is quite annoying if screen brightness changes rapidly, because if the light sensor is covered accidentally by the user's hand.

It is not an option to disable automatic brightness.

I found this: Change brightness according to surrounding light in android But I would prefer to not hack it manually...

Are there nicer options?

有帮助吗?

解决方案

You might want to take a look at these constants

 private static final int BRIGHTNESS_RAMP_RATE_FAST = 200;
 private static final int BRIGHTNESS_RAMP_RATE_SLOW = 40;

and how they're used in DisplayPowerController class which

 Controls the power state of the display. Handles the proximity sensor, light sensor,
 and animations between states including the screen off animation. 

You might also want to take a look at rate parameter of public boolean registerListener (SensorListener listener, int sensors, int rate) as described here

 The rate sensor events are delivered at. This is only a hint to the system. 
 Events may be received faster or slower than the specified rate. 
 Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL,
 SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST or, the desired delay
 between events in microseconds. 
 Specifying the delay in microseconds only works from
 Android 2.3 (API level 9) onwards. For earlier releases, you must use one of the 
 SENSOR_DELAY_* constants.

其他提示

You cannot change the automatic brightness change delay in DisplayManager, nor can you change the curve. You can install one of the market applications which control the brightness and give you more control on how it is done. Check here: https://play.google.com/store/search?q=auto+brightness&c=apps

From here: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3_r1/com/android/server/PowerManagerService.java#PowerManagerService.getAutoBrightnessValue%28int%2Cint%5B%5D%29

SensorEventListener mLightListener = new SensorEventListener() {
2971        public void More ...onSensorChanged(SensorEvent event) {
2972            synchronized (mLocks) {
2973                // ignore light sensor while screen is turning off
2974                if (isScreenTurningOffLocked()) {
2975                    return;
2976                }
2977
2978                int value = (int)event.values[0];
2979                long milliseconds = SystemClock.elapsedRealtime();
2980                if (mDebugLightSensor) {
2981                    Slog.d(TAG, "onSensorChanged: light value: " + value);
2982                }
2983                mHandler.removeCallbacks(mAutoBrightnessTask);
2984                if (mLightSensorValue != value) {
2985                    if (mLightSensorValue == -1 ||
2986                            milliseconds < mLastScreenOnTime + mLightSensorWarmupTime) {
2987                        // process the value immediately if screen has just turned on
2988                        lightSensorChangedLocked(value);
2989                    } else {
2990                        // delay processing to debounce the sensor
2991                        mLightSensorPendingValue = value;
2992                        mHandler.postDelayed(mAutoBrightnessTask, LIGHT_SENSOR_DELAY);
2993                    }
2994                } else {
2995                    mLightSensorPendingValue = -1;
2996                }
2997            }
2998        }
2999
3000        public void More ...onAccuracyChanged(Sensor sensor, int accuracy) {
3001            // ignore
3002        }
3003    };

As you can see, LIGHT_SENSOR_DELAY is a

private static final int LIGHT_SENSOR_DELAY = 2000;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top