如何添加一个动态的图像,而不是通知图标在Android的?图标、而不是、图像、通知

2023-09-07 12:47:18 作者:今天也很乖哦

我用低于code在通知栏中显示通知。

I used below code for displaying notification in notification Bar.

它工作得很好。

但我需要动态显示通知图标,将来自Web服务。

But i need to display notification icon dynamically that will come from web service.

我该怎么办?

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);

在此先感谢。

Thanks in Advance.

推荐答案

我有一个saggestion你:你要下载您想要显示的图像,你可以设置为位图:检查以下code。我已创建了一个位图。 它的外观链接:

i have one saggestion for you: you have to download that image which you want to show and you can set that as bitmap: check below code. i have created one BITMAP. its look link :

有关这一点,你必须添加 Android的支持 - v4.jar

for this you have to add 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此链接的更多细节。

for more detail chekc this link.

删除通知

通知仍然可见,直到发生下列情况之一:

Notifications remain visible until one of the following happens:

用户单独或通过使用全部清除(如果通知可以被清除)。

The user dismisses the notification either individually or by using "Clear All" (if the notification can be cleared).

用户点击该通知,你叫 setAutoCancel()当你创建的通知。 你叫取消()为特定的通知ID。这种方法也将删除正在进行的通知。

The user clicks the notification, and you called setAutoCancel() when you created the notification. You call cancel() for a specific notification ID. This method also deletes ongoing notifications.

您拨打 cancelAll(),它去除了所有通知你pviously发行$ P $。

You call cancelAll(), which removes all of the notifications you previously issued.

编辑:只需更换这种

mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("My notification").setLargeIcon(BITMAP)
                .setAutoCancel(true)
                .setContentText("Hello World!");
 
精彩推荐
图片推荐