Android短屏亮度代码!

问题描述

| 谁知道为什么此代码不会降低我的应用程序的背景光?
Context context = this;

    Settings.System.putInt(context.getContentResolver(),Settings.System.SCREEN_BRIGHTnesS,255);
    

解决方法

        不再允许应用程序修改全局亮度。不要使用人们试图在各个方面提出的技巧,它们使用私有API,并且会在不同设备上以各种方式破坏(并且被视为安全漏洞,该漏洞已在较新版本的平台上关闭)。 设置亮度的官方API是WindowManager.LayoutParams.screenBrightness,它使您可以为自己的应用程序窗口设置亮度。当用户移入和移出您的应用程序时,该平台将自动负责更改亮度。 使用它来更改它:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = <some value between 0 and 1>;
getWindow().setAttributes(lp);
    ,        如果要更改当前应用程序的亮度,请使用发布的代码hackbod
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = <some value between 0 and 1>;
getWindow().setAttributes(lp);
但是我不能完全同意hackbod的帖子。绝对有可能无需使用hack即可更改全局亮度。我只是写了一个简短的演示应用程序。 诀窍在于,首先必须更改应用程序的亮度,然后再更改全局亮度。否则,只有设置菜单中的“亮度滑块”会更改其位置,但这不会影响亮度。仅当用户点击滑块时,才会应用亮度。
    WindowManager.LayoutParams localLayoutParams = getWindow()
            .getAttributes();
    localLayoutParams.screenBrightness = 0.12F;
    getWindow().setAttributes(localLayoutParams);

    Settings.System.putInt(this.resolver,\"screen_brightness\",30);
应用程序亮度范围为0-1 全局亮度范围为0-255(0 =关闭显示) 同样重要的是,如果要稍后退出,请等待一段时间以应用设置。
    Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        System.out.println(e);
                    }
                    System.out.println(\"finally exit\");
                    finish();
                }
            });
    t.start();
    ,        遵循此代码,我想我已经对您先前对此的评论了:) 参考此教程