貼一段調整安卓手機屏幕亮度的代碼 ,可以參考使用,見下:
public void setBrightness(int level) {
ContentResolver cr = getContentResolver();
Settings.System.putInt(cr, "screen_brightness", level);
try {
defaultLevel = Settings.System.getInt(cr, "screen_brightness");
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
Window window = getWindow();
LayoutParams attributes = window.getAttributes();
float flevel = level;
attributes.screenBrightness = flevel / 255;
getWindow().setAttributes(attributes);
}
此外,UiModeManager這個類提供了控制系統UI模式的服務,可以參考使用:
{
UiModeManager uim = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
int i = uim.getCurrentModeType();
if (i != Configuration.UI_MODE_TYPE_CAR) {
uim.enableCarMode(0);
}
uim.setNightMode(UiModeManager.MODE_NIGHT_YES);
}