问题描述
我想改变亮度,我可以用这个方法:
I want to change the Brightness, I can use this method:
public static void SetBright(int brightness, Context context) {
if (isAutoBrightness(context)) {
stopAutoBrightness(context);
}
WindowManager.LayoutParams lp = ((Activity) context).getWindow()
.getAttributes();
lp.screenBrightness = Float.valueOf(brightness) * (1f / 255f);
((Activity) context).getWindow().setAttributes(lp);
}
我需要一个活动传递到 SetBright(INT亮度,上下文的背景下);
但现在我必须调用一个Brocastreceiver方法 SetBright(INT亮度,上下文的背景下)
。我可以使用上下文中的方法的onReceive(上下文的背景下,意图意图),但如果我退出程序,这是行不通的。
But now I have to invoke the method SetBright(int brightness, Context context)
in a Brocastreceiver. I can use the context in the method onReceive(Context context, Intent intent) but if I quit the app, it doesn't work.
有没有我可以用它来改变亮度,而不是期运用活动的另一种方法?
Is there another method that I can use to change the brightness instead of useing an activity?
推荐答案
使用亮度(0到1的范围-1 255)开始虚活动,并设置窗口的参数。
运行50,100或500毫秒的任何一个计时器。之后完成的活动。
start dummy activity and set window parameter using brightness(0 to 1 range-1 for 255).run a timer of 50, 100 or 500 ms whatever. after that finish the activity.
TimerTask finishTask = new TimerTask() {
@Override
public void run() {
BrightActivity.this.finish();
timer.cancel();
if (timer != null) {
timer = null;
}
}
};
timer.schedule(finishTask,Constants.BRIGHTNESS_REFRESH_DELAY);
这篇关于我怎样才能改变广播接收器屏幕的亮度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!