我需要更新通知内容。我怎样才能做到这一点?
我在Thread中这样做:
notificationManager.notify(new Integer(id), notification);
我的通知机构:
Intent notificationIntent = new Intent(this, SingleNewsActivity.class);
notificationIntent.putExtra("id", id);
notificationIntent.putExtra("title", title);
notificationIntent.putExtra("text", text);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, activity, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
activity++;
builder.setContentIntent(contentIntent);
builder.setSmallIcon(R.drawable.ic_bitcoin_notification);
builder.setLargeIcon(bitmap);
builder.setTicker(bar);
builder.setContentTitle(title);
builder.setContentText(text);
builder.setWhen(System.currentTimeMillis());
if(!silent){
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
}
builder.setVibrate(null);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(new Integer(id), notification);
并为3个通知设置唯一的静态ID,但在Thread
中,当我使用notify
时,Android中的通知会更改位置。
如何禁用排序并为我的通知执行静态位置?
Android按优先级顺序排列通知,然后按时间排序。如果您希望保持相对于彼此的通知,请为其提供不同的优先级,或确保时间保持在该顺序中。这些似乎都不是很好的选择,但......
通常不鼓励应用程序同时拥有多个通知。也许你应该寻找一种方法将它们合并为一个。
如果您在通知的构建器中使用“setWhen”,它就可以解决问题
NotificationCompat.Builder builder = new NotificationCompat.Builder( context, "channel_name_here" );
builder.setContentTitle( "My notification" );
builder.setWhen( long uniqueTimeForEveryRequest );
NotificationManagerCompat.from( context ).notify( yourUniqueId, builder.build() );
你可以在android docs https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setWhen(long)中看到更多关于“setWhen”的信息