0

This question has been asked before, but has not been properly answered yet. I know this is possible but we're feeling a little confused.

We need to display custom/dynamic images in the status bar when push notifications are received. We're concerned with the larger image seen in the pull-down, not the small image in the actual status bar. Because they need to be dynamic, the images can not be packaged with the apk and we are trying to target Android 2.2

What we're trying to achieve is similar to how Facebook displays the profile image of the user who initiated the notification in the notification bar. It's also similar to how whatsApp shows the group image in the notification bar when a new push notification arrives.

From what we've read, this is possible only in Android 3+, sdk 11. But that can't be true.

We've installed both Facebook and WhatsApp on an Android phone running 2.3.4 and sure enough, custom icons display in the notification bar.

So what's the secret? How do they do it? How can we do it?

Ryan Martin
  • 1,613
  • 3
  • 24
  • 36

2 Answers2

2

so what you are trying to do is set the setLargeIcon(Bitmap icon) in the notification builder. This is available in APi 11 and above (honeycomb). The notification builder in the compatibility package v9 can set it for you, but it will only appear on api 11 and above. To achieve the same effect in 2.3 and below you must create a custom notification layout and set it with setContent(RemoteViews views) in Notification.Builder to generate a custom layout. This can be styled with a large icon on the left side to imitate the > API 11 styles.

Creating custom layouts is tricky and many things have to be taken into account, such as available screen size on other devices to display the notification, and themed text colors (especially as notifications used to be dark text on white bg, now they are light text on dark bg) There plenty of guides and even SO posts that can help you out (such as this one)

In regards to getting a dynamic image, when the phone receives the message (push notification or whatever) and your app goes to build the notification, you can do a small http request to pull a dynamic image before building the notification. This will delay the posting a few seconds, but it doesn't really matter. Then you can get the resulting image and use it in the notification. The specific image can be chosen by sending some data with the (im assuming push notification) that identifies what photo, such as a url, or an id that you can append onto an already existing url in your notification building part of the app.

Hope this helps, any followups just ask :)

Community
  • 1
  • 1
Glenn.nz
  • 2,261
  • 2
  • 17
  • 20
  • This is exactly the solution we were looking for. Following your answer we were able to do almost exactly what you described. We send the URL of the image as part of the extra push data, make the call and set the image. It works perfectly, even in 2.3 :-) Thanks so much! – Ryan Martin Jul 18 '12 at 23:27
-1

You can't use anything but prepackaged drawables as your notification icon as seen on status bar. And no, you did not see anything like you look for in FB app (or you talk about notification area seen when you pull it down).

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • I'm not sure I understand what you're trying to say. My question is specific to the large icon seen in the pulldown, not the small icon. And if you're suggesting that Facebook and WhatsApp have actually not achieved what I'm suggesting, you're completely incorrect. – Ryan Martin Jul 17 '12 at 20:54
  • I am very correct, but you seem to not understand what you ask for. Notification area (aka titlebar etc) is top most area (on phones), visible all the time (besides full screen mode). That one with sysytem clock, carrier bars etc. Icons you see there cannot be dynamic as I told you. API accepts resource id for the icon so you're doomed. The other thing is notification area which user can unfold by dragging titlebar down. And you can have your own layout there, so nothing prevents you from putting ImageView in that layout and then display whatever image you want with it. – Marcin Orlowski Jul 18 '12 at 10:30
  • 1
    I state very clearly in the post that "We're concerned with the larger image seen in the pull-down, not the small image in the actual status bar." Did you even read it? If you don't have an answer, why post an answer at all - and a smug one at that? Trying to increase your reputation? Dirty. – Ryan Martin Jul 18 '12 at 16:49
  • Looks I am wasting my time trying to help you. I already gave you clear and valid answer in previous comment. If you got problems understanding it, ask your devs what it all means. – Marcin Orlowski Jul 18 '12 at 17:50
  • You have the poorest interpretation of questions ive ever seen... Please think about your answer for just a second... – Glenn.nz Jul 18 '12 at 21:17