I have created notification with one action button in my application which works fine in devices below 6.0 but above 6.0 the action button is not getting clicked but instead the whole notification gets clicked and the content intent is fired instead of action buttons pending intent,does any one know how to use action button in Marshamallow and above.
Below is my code:-
Intent downloadCancel = new Intent();
downloadCancel.setAction("CANCEL");
PendingIntent cancelPI = PendingIntent.getBroadcast(this,1,downloadCancel, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
Notification.Action actionButton = new Notification.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel,"Cancel",cancelPI).build();
notification = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.ic_file_download_white_24dp)
.setContentIntent(pendingIntent)
.setTicker(text)
.setWhen(0)
.setPriority(Notification.PRIORITY_MAX)
.addAction(actionButton).getNotification();
}
else
{
notification = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.ic_file_download_white_24dp)
.setContentIntent(pendingIntent)
.setTicker(text)
.setWhen(0)
.setPriority(Notification.PRIORITY_MAX)
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", cancelPI).getNotification();
}
I had to use remoteViews for this issue no other options were there