更改屏幕亮度的onPause(Android应用程序) [英] Change screen brightness onPause (Android app)

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

问题描述

我的应用程序节省了用户原有的亮度:

My app saves the user original brightness with:

originalBrightness = Settings.System.SCREEN_BRIGHTNESS;

,然后改变它,而程序运行。

and then changes it while the program running.

originalBrightness是私有的全局字符串。

originalBrightness is private global string. Now what I am trying to do is when the user clicks on "Home" or when the app paused the original screen is need to be set again, I have tried to do this like this but the app crushes:

public void onPause() {
    super.onPause();
    int brightness = Integer.getInteger(originalBrightness);
    setBrightness(brightness);
}
private void setBrightness(int brightness) {
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = brightness / 100.0f;
    getWindow().setAttributes(layoutParams);
}

有没有去男性工作?谢谢

Is there away to male it work? Thanks

推荐答案

请尝试使用 Settings.System.SCREEN_BRIGHTNESS 来设置系统默认亮度为:

Try Using Settings.System.SCREEN_BRIGHTNESS to set system default brightness as:

android.provider.Settings.System.putInt(getContentResolver(),  
android.provider.Settings.System.SCREEN_BRIGHTNESS,brightness /100.0f); // 0-255 

和清单中添加这些权限的:

and add these permission's in manifest :

<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

这篇关于更改屏幕亮度的onPause(Android应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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