Change the color of the status bar without a window

I want to manage the status bar (ex.color), but in the background. I use the foreground service for this. Thus, there is no window, as this happens in the background, in particular, there is no activity. However function

public abstract void setStatusBarColor (int color) 

called by the abstract Window class: https://developer.android.com/reference/android/view/Window.html

And because it is abstract, I cannot initiate it, and I cannot use getWindow (), since I do not implement an activity class. The following answer uses Activity. Is there any other way to implement this? How to change status bar color in android

+7
android statusbar android-windowmanager android-statusbar
source share
1 answer

And because it ( setStatusBarColor() ) is abstract, I cannot initiate it, and I cannot use getWindow()

You should not create an instance of the Window class yourself, this is what you should get from the framework, in particular from your activity. As long as you do not , you cannot get a reference to the Window instance.

Assuming that the process of your application is not in the foreground (i.e. there is no visible activity), then you have no way to change the color of the status bar.

Imagine that the structure would allow such things to be done, then it could be misused by malicious applications to randomly change the color of the status bar every second when the user did not even open the malicious application. I think this will be considered a disadvantage, not a feature.

+6
source share

All Articles