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.
Start a new transparent
Activity
, adjust the brightness value (of both theWindow
and system settings), then callfinish()
on theActivity
. This will steal focus from the user in some cases, no matter what flags you use.Create a persistent transparent system-wide overlay using a
Dialog
and the flagWindowManager.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.
精彩评论