停止排序 Android 条通知
Stop sorting Android Notifications
我需要更新通知内容。我该怎么做?
我在线程中这样做:
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 文档中查看有关 "setWhen" 的更多信息 https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setWhen(long)
我需要更新通知内容。我该怎么做?
我在线程中这样做:
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 文档中查看有关 "setWhen" 的更多信息 https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setWhen(long)