2

I've been toying around with the Android 5.0 Lollipop APIs, when I came across Window#getStatusBarColor(). However, this requires an instance of Window say from an Activity, so it can't be used in a background service. Is there a way for an app to detect the status bar color on Android 5.0?

Update:

As Nikola Despotoski mentioned, there is the createScreenCaptureIntent method which could do the trick by "screen recording," and just checking the status bar region.
As it turns out, the return value of this method if passed to startActivityForResult. The initial request is meant to be called from an Activity.
Even if the result was saved and passed to a Service, there would need to be some complex pattern to re-ask for permission every time it was needed. There also doesn't seem to be a synchronous way to obtain a Bitmap. In the background, this means always processing screen changes just to obtain a single pixel.

Tom
  • 6,947
  • 7
  • 46
  • 76

1 Answers1

1

Interesting question.

You can make use of new Lolipop screen capture API. Using createScreenCaptureIntent() and MediaProjectionManager to retrieve the Bitmap.

Once you have the bitmap, try to cut (decode) the Bitmap from top=0 to bottom=status_bar_height. Pass the cut Bitmap to Palette and retrieve the color using getRGB() method.

Community
  • 1
  • 1
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • I thought about this, but it seemed excessively complicated and expensive in terms of CPU (especially in the case of fast app switching). – Tom Dec 15 '14 at 01:13