我有一个自定义布局通知,用于填充一些数据(距离数据)。
我必须更新现有通知中的距离。
当我更新它时,我的自定义布局会更改为默认的Android通知布局。
新通知创建代码。
remoteViews = notificationCustomUI(poi_name, formatDistanceText(poi_type, distance), left_action, right_action, pendingLeftIntent, pendingRightIntent);
notificationBuilder = new NotificationCompat.Builder(this); // creating new builder for new notification.
notification = notificationBuilder.setSmallIcon(R.mipmap.launcher)
.setContentText(formatDistanceText(poi_type, distance))
.setContentTitle(poi_name)
.setSmallIcon(getNotificationIcon())
.setLargeIcon(largeIcon)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingLeftIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDeleteIntent(getDeleteIntent(notificationId, poi_id, poi_type))
.build();
notification.bigContentView = remoteViews;
notificationManager.notify(notificationId, notification);
更新退出通知代码
remoteViews.setTextViewText(R.id.tv_distance, formatDistanceText(poi_type, distance));
notificationManager.notify(existingNotificationId, notificationBuilder.build());