问题
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.
来源:https://stackoverflow.com/questions/49979848/android-notification-actions-with-notification-channeling