【问题标题】:cannot set brightness for application [duplicate]无法为应用程序设置亮度[重复]
【发布时间】:2018-01-03 11:07:05
【问题描述】:

我正在编写一个应用程序来使用搜索栏更改屏幕亮度,我在事件 onProgressChanged 上使用此代码

Settings.System.putInt(getApplicationContext().getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,newBrightness);

但是在这段代码之后应用程序崩溃了。我也加了

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

有人知道为什么吗?请帮帮我

提前致谢

【问题讨论】:

    标签: android brightness


    【解决方案1】:

    您也应该刷新屏幕。比你的代码更复杂。

    Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 20);
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = 0.2f;
    getWindow().setAttributes(layoutParams);
    startActivity(new Intent(this,RefreshScreen.class));
    

    您可能还需要关闭自动模式:

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

    【讨论】:

      猜你喜欢
      • 2012-03-19
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 2018-09-06
      相关资源
      最近更新 更多