Question

I use NotificationCompat.Builder in an Activity and setAutoCancel(true) works fine, but the same is not working inside a BroadcastReceiver -the notification just keep showing up in the device regardless how many times the user clicks it. How to disable the notification upon user clicks in this case?

I also using this code together with the above and not working. PendingIntent pi=PendingIntent.getActivity(context, 0, dailyIntent, PendingIntent.FLAG_CANCEL_CURRENT);

Builder.setContentIntent(pi);

Was it helpful?

Solution

What you are doing is setting up an acitivity pending intent. It will launch activity upon clicking the notification. Change your PendinIntent to send broadcast like this:-

pi = PendingIntent.getBroadcast(context, 0, dailyIntent,
                                PendingIntent.FLAG_CANCEL_CURRENT); 

         // notice getBroadcast()

where dailyIntent is an intent for broadcast. This will send the mentioned broadcast intent upon clicking the notification.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top