2015-09-21 60 views
1

我使用此代码来降低屏幕亮度,但它只适用于Android 4.4--。当我在android 5 ++中测试时,当它完成/关闭Activity后,它会在Activity打开时工作,然后屏幕亮度将返回默认设置。如何在Android 5.0 ++中保持屏幕亮度设置无法保持屏幕亮度设置在android 5.0 ++

cResolver = getContentResolver(); 
    window = getWindow(); 
    android.provider.Settings.System.putInt(cResolver, 
      android.provider.Settings.System.SCREEN_BRIGHTNESS,75); 
    WindowManager.LayoutParams layoutpars = window.getAttributes(); 
    layoutpars.screenBrightness = 75/(float) 255; 
    window.setAttributes(layoutpars); 

回答

0

设备上是否启用了自适应亮度?这将意味着亮度级别落在用户定义的范围内,而不是使用您提供的单个值。在运行您发布的代码之前尝试禁用它,并查看它是否有所作为。

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

此外,请参阅this question以获取在启用自适应模式时更改值的帮助。