13

I wanted to create a notification without the icon in the status bar (the state that is not expanded). I tried the custom expanded view and set the icon for this view only. But it did not work. When I give 0 as icon to the constructor, the icon disappears but notification also does not appear in the expanded view.

Notification notification = new Notification(0, "", 0);

I tried a lot of combinations but didn't come out with a solution. By the way, I know it is working because I saw this feature in some apps. Thanks.

Brandon
  • 16,382
  • 12
  • 55
  • 88
Ömer
  • 1,666
  • 2
  • 18
  • 33

4 Answers4

25

This is now possible in Android 4.1; the reference implementation of the Jelly Bean status bar will suppress icons for PRIORITY_MIN notifications, although their content will still show in the notification panel.

dsandler
  • 2,471
  • 17
  • 11
6

QuickSettings did this and as I looked at that code I saw it uses the default constructor of Notification and pushes its icon to the right of the notification bar. I think it still uses space but has no icon.

Some code:

notification = new Notification();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
long hiddenTime = Constants.SDK_VERSION >= 9 ? -Long.MAX_VALUE : Long.MAX_VALUE;
notification.when = visible ? System.currentTimeMillis() : hiddenTime; // align
// left (0) / right (max) in status bar

edit: oh sorry I missed an important line of code, in fact he uses a placeholder. But now you have some code ;-)

notification.icon = visible ? (status == Constants.STATUS_BLACK_ICON ? 
                            R.drawable.ic_logo_black : R.drawable.ic_logo_white)
                            : R.drawable.ic_placeholder;

http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
ludwigm
  • 3,363
  • 3
  • 28
  • 36
  • a smart hack actually. Thanks :) – Ömer Dec 23 '10 at 04:53
  • @ludwigm, QuickSettings code is not available anymore, can you elaborate a little bit more about the solution. I didn't fully understand how things really work. – Efi MK Jun 04 '12 at 21:51
  • 1
    Found the source code here - http://www.java2s.com/Open-Source/Android/Tools/quick-settings/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java.htm – Efi MK Jun 05 '12 at 06:03
  • 1
    That is down too, found a copy here: https://github.com/yanchenko/quick-settings/blob/master/src/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java – arne.jans May 21 '15 at 09:33
0

Here's something to experiment with. Put up a notification twice, once with icon=0 and once with a real icon. Try it in one order and then in the opposite order.

I got the effect of no notification in status bar and notification in expanded list when I did something like this, except that one of the two (the one with icon=0) was put up by Service.startForeground(). I don't have time to experiment more right now.

Alexander Pruss
  • 365
  • 3
  • 10
0

You could use a transparent images as the notification icon. but as molnarm already mentioned, the user won't notify that there is a new notification

  • This is not possible, even though you gave an icon in 1 pixel dimension. it reserves what it should be and displays it white. – Ömer May 18 '10 at 10:44
  • I just don't want to reserve an area there. It is doesn't matter black, white or transparent. – Ömer May 18 '10 at 11:33