使用不同的参数调用了下面的方法两次,name
但我的设备上只出现了 1 个通知(最后一个)。PendingIntent.getActivity()
我认为在其中放置一个唯一的请求模式参数name.hashCode()
会起作用,但这并没有解决问题。那么如何更改此方法以使我的设备连续显示 2 个通知而不是仅显示最后一个?
private void showNotification(String name, String sub) {
Intent intent = new Intent(activity.getApplicationContext(),
FragmentTabsPager.class);
PendingIntent pIntent = PendingIntent.getActivity(
activity.getApplicationContext(), name.hashCode(), intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
activity.getApplicationContext());
builder.setContentTitle("Hello world"
).setContentText(name+" from "+sub)
.setSmallIcon(R.drawable.icon).setContentIntent(pIntent)
.getNotification();
NotificationManager notificationManager = (NotificationManager) activity
.getApplicationContext().getSystemService(
Context.NOTIFICATION_SERVICE);
Notification notification = builder.getNotification();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}