setAutoCancel(true) doesnot work

630 Views Asked by At

Hi all my android push notification works well.but if there is only one notification for my app ,after user touches it it cleared.but if multiple notifications are there (by using id) only first one clear after touching some notifications are still showing in satusbar.I use NotificationCompat.Builder so i needed to use .setAutoCancel(true). Here is my code (Please Note 'collapse_key' is a integer between 1 to 12 and it is not the collapsekey in GCM concept)

 @Override
    protected void onMessage(Context ctx, Intent intent) {
        int myId;
        Log.d("Time",""+System.currentTimeMillis());
        Intent intenti = new Intent(Intent.ACTION_MAIN);
        intenti.putExtra("k12grade",intent.getStringExtra("k12grade"));
        Log.d("NOT:","k12garde="+intent.getStringExtra("k12grade"));
        intenti.setClass(this.getBaseContext(),QuizByteGradeRankersActivityPush.class);
        intenti.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent sender = PendingIntent.getActivity(this.getBaseContext(), 192839, intenti, PendingIntent.FLAG_UPDATE_CURRENT);
         NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle("New Top Ranker!")
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setContentText(intent.getStringExtra("message"))
                        .setAutoCancel(true)
                        .setContentIntent(sender)
                        .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(intent.getStringExtra("message")));
        myId=Integer.parseInt(intent.getStringExtra("collapse_key"));
        Log.d("NOT:","collapse key="+myId);
        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
         mNotificationManager.notify(myId, mBuilder.build());




    }
0

There are 0 best solutions below