私は各フォトアルバムの更新に関する通知を表示しているプロジェクトに取り組んでいます。しかし、ある通知をタップすると、通知バーからすべての通知が削除されます。通知を1回タップしてすべての通知を削除
私は、次のコードを試してみました:私は間違って
private void handleNotification(NotificationModel notificationModel) {
// display the notification in the notification bar
int i=0;
if(!TextUtils.isEmpty(notificationModel.getAlbum_id()))
i=Integer.parseInt(notificationModel.getAlbum_id());
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
//icon appears in device notification bar and right hand corner of notification
builder.setSmallIcon(R.mipmap.ic_launcher);
Intent intent=new Intent(this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(MainActivity.BUNDLE_ALBUM_ID_KEY, notificationModel.getAlbum_id());
intent.putExtra(MainActivity.BUNDLE_ALBUM_NAME_KEY, notificationModel.getAlbum_title());
/*intent = new Intent(this, NotificationActivity.class);*/
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),i,intent,PendingIntent.FLAG_UPDATE_CURRENT);
// Set the intent that will fire when the user taps the notification.
builder.setContentIntent(pendingIntent);
/*builder.setAutoCancel(true);*/
// Large icon appears on the left of the notification
builder.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ic_launcher));
// Content title, which appears in large type at the top of the notification
builder.setContentTitle(notificationModel.getTitle());
builder.setContentText(notificationModel.getMessage());
builder.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification=builder.build();
notification.defaults = Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(i,notification);
}
何をしているのですか?
または私のチェック値が問題の可能性がある毎回同じである... –
@MohdSaquibはそれを試みました。動作しません。 i値もチェックしました。ユニークです。 – Subhra
@Subhraあなたのコードは正常に動作しています。別のデバイスで同じプロジェクトを確認するか、デバイスの通知設定を確認してください。 – Nikhil