在Android的屏幕亮度值 [英] Screen brightness value in Android

查看:290
本文介绍了在Android的屏幕亮度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何让你的活动的当前屏幕亮度?

How do you get the current screen brightness of your activity?

以下方法工作正常,通过调用设置亮度为最大 setBrightness(100)

Following method works fine for setting the brightness to max by calling setBrightness(100):

private void setBrightness(int brightness) {
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = brightness/100.0f;
    getWindow().setAttributes(layoutParams);
}

我试着去实现以下目标:

Im trying to achieve the following:

  1. 启动活动和保存当前亮度值
  2. 设置亮度最大值
  3. 重置亮度对某些事件的初始值

非常感谢!

推荐答案

尝试

int curBrightnessValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);

然后

   WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = curBrightnessValue/100.0f;
    getWindow().setAttributes(layoutParams);

这篇关于在Android的屏幕亮度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆