如何更改android屏幕亮度持续?

时间:2011-06-01 02:27:16

标签: android brightness screen-brightness

我已设法使用以下代码更改活动中的屏幕亮度(以及扩展整个应用):

Settings.System.putFloat(this.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, ((float)LocationService.settings.screenBrightness));

WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness = someValue;
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);

但是,只要关闭应用程序,亮度就会恢复到以前的设置。无论如何,这些更改是否会在应用程序的生命周期之外持续存在?

谢谢!

4 个答案:

答案 0 :(得分:0)

这里可以帮到你:

WindowManager.LayoutParams layoutParams = getWindow().getAttributes();  
layoutParams.buttonBrightness = value;
getWindow().setAttributes(layoutParams);

答案 1 :(得分:0)

试试这个

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

int brightnessLevel = 255;
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightnessLevel);

您需要在AndroidManifest.xml中设置WRITE_SETTINGS权限

http://android-er.blogspot.com/2011/02/change-system-screen-brightness-using.html

答案 2 :(得分:0)

设置应用程序就是这样做的:

private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON;

System.putInt(getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, value + MINIMUM_BACKLIGHT);

但我怀疑在没有系统共享用户ID的情况下无法更改系统设置

答案 3 :(得分:0)

在androidMainfest.xml中提供权限

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

并提供0到255之间的整数

//number>=0 && number<=255
//If you have passed context then you can use context.getContentResolver()
android.provider.Settings.System.putInt(cgetContentResolver(),
            android.provider.Settings.System.SCREEN_BRIGHTNESS,
            number);