1

I am working on an application where we have to generate a notification with action buttons. It was working fine till the date we decided to update our notification handling to support notification channels (released with Android Oreo 8.0). I don't know if this is the reason or there is something missing in our implementation that made notification action buttons unResponsive.

Below mentioned is the code snippet...

NotificationCompat.Builder localCallNotificationBuilder = new NotificationCompat.Builder(mContext, <channelId>);

Intent intent = new Intent();
intent.setAction(IAppConstant.ICallingAction.INTENT_ACTION_DO_CANCEL);
PendingIntent pendingIntentHangUp = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
localCallNotificationBuilder.addAction(0, mRes.getString(R.string.label_cancel), intent);

localCallNotificationBuilder.setContentText(notificationContent)
            .setTicker(notificationContent)
            .setOnlyAlertOnce(true)
            .setSmallIcon(R.drawable.notification_bar_icon)
            .setLargeIcon(userImageBitmap)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationContent))
            .setOngoing(true);

notificationManager.notify(IAppConstant.IGenericKeyConstants.CALL_NOTIFICATION_ID, localCallNotificationBuilder.build());

I have a receiver class where I am listening to this "INTENT_ACTION_DO_CANCEL". But this receiver is never called.

P.S. I tried the solution mentioned in the link Pending intent is not working on Android O but with no success.

EDIT

Below mentioned is the updated action (with explicit intent as per suggestion mentioned in the link

Intent intentAction = new Intent(mContext, NotificationActionReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intentAction, PendingIntent.FLAG_UPDATE_CURRENT);
localCallNotificationBuilder.addAction(0, mRes.getString(R.string.label_cancel), pendingIntent);

<!-- Notification Action Receiver(Manifest entry) -->
<receiver android:name=".reciever.NotificationActionReceiver" />

I am sure there is something missing which I am not able to figure out.

AndoAiron
  • 694
  • 5
  • 19
  • 1
    "I tried the solution" -- not according to the code in the question. If you tried an explicit `Intent`, show that code. – CommonsWare Apr 23 '18 at 19:52
  • @CommonsWare Updated my code to include explicit intent. – AndoAiron Apr 24 '18 at 02:45
  • You have `.reciever.NotificationActionReceiver`. `receiver` != `reciever`. Make sure that your manifest entry matches the actual package name. – CommonsWare Apr 24 '18 at 10:01
  • Yeah there isn't any issue with the receiver entry. I have cross checked too and it is working absolutely fine on Android OS < O. – AndoAiron Apr 24 '18 at 11:46
  • How are you testing that the receiver is/is not called? For example, if the receiver raises a `Notification`, perhaps the problem is with that code (e.g., not using a notification channel). – CommonsWare Apr 24 '18 at 20:10
  • @CommonsWare Receiver is there just to respond to notification actions. I had added logs in the receiver to verify if it is being called or not. I tried to launch an activity directly from notification actions using pendingIntent for an activity but without any luck.. – AndoAiron Apr 30 '18 at 06:39
  • @CommonsWare : It is working as expected with your suggestion of using an Explicit intent. However, I was doing the same before posting this question but somehow it wasn't working at that time. Thanks for your time and valuable feedback. – AndoAiron May 08 '18 at 08:31
  • 1
    @AndoAiron can you please update with your working code as answer? – williamj949 Feb 06 '19 at 08:38

0 Answers0