简体   繁体   中英

How to access the Window when not an activity?

I want to access the Window class so I can set the screen brightness on my phone. The problem is that the class I want to do this from is not an activity. Is it possible to do this without being an activity? I have a context and a content resolver, if that helps.

Thanks in advance!

You have two options here.

  1. Start a new transparent Activity , adjust the brightness value (of both the Window and system settings), then call finish() on the Activity . This will steal focus from the user in some cases, no matter what flags you use.

  2. Create a persistent transparent system-wide overlay using a Dialog and the flag WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY . This can cause odd issues like blocking the installation of apps.

In other words, there's no clean way of doing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM