I am currently trying to figure out how to change the screen brightness via a non-activity class.
I found this method here on stackoverflow:
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = curBrightnessValue/100.0f;
getWindow().setAttributes(layoutParams);
Now the problem is, I can't access the getWindow() method from my class because it doesn't extend and activity. The call looks a bit like this:
BrightnessClass.changeBrightness(context);
and the method in the BrightnessClass looks as following:
public static void changeBrightness(Context context, int v) {
//Change brightness here
}
Now how can I access the getWindow() method via context, is there a way? Or do I have to hand over an activity-instance to call this method?
Thanks in advance
EDIT: the method is called by a service. That's why I have a context but not an activity to pass.