android的通知不出现

我用下面的实现代码显示android中的一些通知,是参照一些网络教程的。但是通知没显示出来,我试了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个回答

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

你把.setLargeIcon(largeIcon)去掉试试,可能是因为图片太大的原因!!

立即提问