【发布时间】:2011-09-03 18:10:11
【问题描述】:
有谁知道为什么这段代码没有降低我的应用程序的背光?
Context context = this;
Settings.System.putInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, 255);
【问题讨论】:
有谁知道为什么这段代码没有降低我的应用程序的背光?
Context context = this;
Settings.System.putInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, 255);
【问题讨论】:
按照这段代码,我想我已经对你之前的问题发表了评论:)
请参考tuto
【讨论】:
不再允许应用程序修改全局亮度。不要使用人们试图在各个方面提出的技巧,这些技巧使用私有 API,并且会在不同设备上以各种方式破坏(并且被认为已在更新的平台版本上关闭的安全漏洞)。
设置亮度的官方 API 是 WindowManager.LayoutParams.screenBrightness,它允许您为自己的应用程序窗口设置亮度。当用户进出您的应用时,该平台会自动调整亮度。
用这个来改变它:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = <some value between 0 and 1>;
getWindow().setAttributes(lp);
【讨论】:
lp.screenBrightness = -1; 将亮度设置回自动。
如果您想更改当前应用程序的亮度,请使用发布的代码 hackbod
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = <some value between 0 and 1>;
getWindow().setAttributes(lp);
但我不能完全同意 hackbod 的帖子。绝对有可能在不使用黑客的情况下改变全局亮度。我刚刚写了一个简短的演示应用程序。
诀窍是,首先必须更改应用程序的亮度,然后再更改全局亮度。否则只有设置菜单中的“亮度滑块”会改变其位置,但这不会影响亮度。只有当用户点击滑块时,才会应用亮度。
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();
【讨论】: