0

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.

user2410644
  • 3,861
  • 6
  • 39
  • 59

1 Answers1

0

You are trying to change system brightness but you are changing the window brightness. And window is only in activity not in service. If you want to change System brightness then you can refer through this answer.

Community
  • 1
  • 1