Android通知不会显示

时间:2012-12-13 07:32:12

标签: android

我已经实现了以下方法在android中显示一些通知。该方法与developer.android.com教程非常相似,但我的通知不会出现在4.1或4.0或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());
}

2 个答案:

答案 0 :(得分:6)

small icon是通知的必需元素。

builder.setSmallIcon(R.drawable.notification_icon);

这是状态栏中显示的图标。

答案 1 :(得分:0)

试试这个:

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