Neil Walker
Neil Walker

Reputation: 6848

Android Notification not fired with no small icon or has no message if small icon set

I'm creating a notification as per the code below. When I run it all I get across the top of the device (avd) is the small icon with no text (I'd have thought 'From Neil' to be displayed) but the notification is full and complete when I drag down to show the notification page.

However, if I comment out the setSmallIcon the notification isn't even created and nothing happens. What's going wrong? Thanks.

private void doNotification() {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    b.setContentTitle("From Neil");
    b.setContentText("Hello email from neil");
    b.setSmallIcon(android.R.drawable.ic_dialog_alert);         


    //do not want an intent fired
    pIntent = PendingIntent.getActivity(this, 0, new Intent(), 
            PendingIntent.FLAG_UPDATE_CURRENT);     

    b.setContentIntent(pIntent);

    Notification n=b.build();
    n.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notificationManager.notify(0, n);   
}

Upvotes: 2

Views: 3197

Answers (1)

dsandler
dsandler

Reputation: 2481

What you're seeing is correct behavior: The status bar simply adds your small icon to the notification area. You're probably thinking of the tickerText, which if set will cause some text to scroll by when the notification is first posted. Call setTicker("From Neil"), or perhaps more informatively "Neil: Hello email from neil" on your Notification.Builder.

Upvotes: 5

Related Questions