2 bluetooth99 bluetooth99 于 2012.12.13 16:41 提问

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个回答

cytown
cytown   2012.12.13 18:16
已采纳

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

u011724096
u011724096   2014.08.22 15:28

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!