如何在android中添加动态图像而不是通知图标?

我使用下面的代码在通知栏中显示通知.

它工作得很好.

但我需要动态显示来自Web服务的通知图标.

我该怎么办?

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Notification note = new Notification(R.drawable.image,"status message", System.currentTimeMillis());

        Intent in = new Intent(Notify.this,CommentU.class);
        PendingIntent pi = PendingIntent.getActivity(Notify.this, 0, in, 0);
        note.setLatestEventInfo(Notify.this,"NotificationTitle", "You have a new Commentio", pi);
        note.number = ++count;
        note.vibrate = new long[] { 500l, 200l, 200l, 500l };
        note.flags |= Notification.FLAG_AUTO_CANCEL;
        nm.notify(NOTIFY_ME_ID, note);

提前致谢.

最佳答案 我有一个建议:您必须下载要显示的图像,然后将其设置为位图:检查下面的代码.我创建了一个BITMAP.

它的外观链接:

为此你必须添加android-support-v4.jar

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("My notification").setLargeIcon(BITMAP)
                .setContentText("Hello World!");

        Intent resultIntent = new Intent(this, test.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

        stackBuilder.addParentStack(test.class);

        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        mNotificationManager.notify(NOTIFY_ME_ID, mBuilder.build());

更多细节chekc这link.

删除通知

在发生以下情况之一之前,通知仍然可见:

用户单独或使用“全部清除”(如果可以清除通知)解除通知.

用户单击通知,并在创建通知时调用setAutoCancel().
您可以为特定通知ID调用cancel().此方法还会删除正在进行的通知.

您调用cancelAll(),它会删除您之前发出的所有通知.

编辑:只需替换它.

mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("My notification").setLargeIcon(BITMAP)
                .setAutoCancel(true)
                .setContentText("Hello World!");
点赞