以下のメソッドは異なるパラメーターで 2 回呼び出されていname
ますが、デバイスには 1 つの通知 (最後の通知) しか表示されません。PendingIntent.getActivity()
独自のリクエスト モード パラメータをwith内に入れる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);
}