2017-08-11 3 views
0

私は各フォトアルバムの更新に関する通知を表示しているプロジェクトに取り組んでいます。しかし、ある通知をタップすると、通知バーからすべての通知が削除されます。通知を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); 
} 

何をしているのですか?

+0

または私のチェック値が問題の可能性がある毎回同じである... –

+0

@MohdSaquibはそれを試みました。動作しません。 i値もチェックしました。ユニークです。 – Subhra

+0

@Subhraあなたのコードは正常に動作しています。別のデバイスで同じプロジェクトを確認するか、デバイスの通知設定を確認してください。 – Nikhil

答えて

0

ここ

int i=0; 
    if(!TextUtils.isEmpty(notificationModel.getAlbum_id())) 
     i=Integer.parseInt(notificationModel.getAlbum_id()); 

「i」が、私は思うの値を確認してください ...「私は」それは通知IDとして動作していることが問題になる可能性があるたびに同じままの値を確認してくださいそのあなたは以下のコードを使用しているあなたのケースでは常に同じ

PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),**i**,intent,PendingIntent.FLAG_UPDATE_CURRENT); 

そして

notificationManager.notify(i,notification); 
+0

「i」の値を確認しました。ユニークです。 'i'が同じ場合、アルバムごとに別々の通知が作成されることはありません。アルバムごとに別々の通知が表示されます。 – Subhra

+0

はい、私は一意ではないはずの主な問題の値です。私は彼女が通知IDの論理値を理解しようとする解決策を与えていることを見てください。つまり、私はあなたのコードで毎回異なるはずです。 私の価値があなたが望むものを達成することができるときとは違うとき。 –

関連する問題