开发者

How to access the Window when not an activity?

I want to 开发者_JS百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜