Android 背光亮度设置

public static final int BRIGHTNESS_DIM = 20;
public static final int BRIGHTNESS_ON = 255;
private static final int MINIMUM_BACKLIGHT = BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = BRIGHTNESS_ON;
progress.setMax(MAXIMUM_BACKLIGHT); //总亮度范围
 
int nBacklight = MAXIMUM_BACKLIGHT;
try
{
 nBacklight = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
}
catch(SettingNotFoundException e)
{
 e.printStackTrace();
} 
progress.setProgress(nBacklight);//显示当前亮度
 
//一定不能设置为0,否则会黑屏,且会立即进入休眠
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, nBacklight);
WindowManager.LayoutParams lpParam = getWindow().getAttributes();
lpParam.screenBrightness = Float.valueOf(nBacklight) * (1f / 255f);
getWindow().setAttributes(lpParam);      
progress.setProgress(nBacklight);

 

上一篇:Toad for SQL Server 优化记录


下一篇:java – Android:使用相机检测手机周围的亮度(光线量)?