endian
endian

Reputation: 4879

Android Notifications won't show up

I've implemented following method for showing some notifications in android. The method is very similar to the developer.android.com tutorial, but my notifications won't show up, neither on 4.1 nor on 4.0 or 2.3.

public void showNotification() {
    String appname = "App Name";
    String title = "Notification Title";
    String text = "This is the notification text";
    String iconUrl = "http://url.to.image.com/image.png";
    Bitmap largeIcon = imageCache.getBitmap(iconUrl);
    NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    TaskStackBuilder stackBuilder = TaskStackBuilder.from(context);
    stackBuilder.addParentStack(NewsActivity.class);
    stackBuilder.addNextIntent(new Intent(context, NewsActivity.class));
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(title).setContentInfo(appname).setLargeIcon(largeIcon).setContentText(text).setContentIntent(pendingIntent);

    notifyManager.notify("textid", 123, builder.getNotification());
}

Upvotes: 2

Views: 1344

Answers (2)

Winnie
Winnie

Reputation: 769

try this:

notifyManager.notify("textid", 123, builder.build());

Upvotes: 0

Andy McSherry
Andy McSherry

Reputation: 4725

A small icon is a required element of the notification.

builder.setSmallIcon(R.drawable.notification_icon);

This is the icon that shows up in the status bar.

Upvotes: 6

Related Questions