Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: No icon for Notification

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.

like image 776
Ömer Avatar asked May 18 '10 07:05

Ömer


People also ask

Why is notification not showing in the icon?

Turn on App icon badges from Settings. Navigate back to the main Settings screen, tap Notifications, and then tap Advanced settings. Tap the switch next to App icon badges to turn them on.

How do you add icons to push notifications?

Navigate to Messages > New Push > Platform Settings > Google Android Options > Set the icon name without the file extension. With Large Notification Icons, you can also supply a URL where the icon will be displayed from.


2 Answers

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.

like image 99
dsandler Avatar answered Sep 27 '22 19:09

dsandler


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

like image 22
ludwigm Avatar answered Sep 27 '22 17:09

ludwigm