What is the proper way to add an action to the notification in API 23
since addAction(int icon, CharSequence title, PendingIntent intent)
is deprecated ? Couldn't find any example, thank you.
My old action: .addAction(R.drawable.ic_prev, "Previous", prevPendingIntent)
This method is deprecated. use Builder(Context, String) instead. All posted notifications must specify a NotificationChannel ID.
Set the small icon resource, which will be used to represent the notification in the status bar. Set the small icon, which will be used to represent the notification in the status bar and content view (unless overridden there by a large icon ).
Instead of this one:
addAction (int icon, CharSequence title, PendingIntent intent)
This method was deprecated in API level 23.
Use:
addAction (Notification.Action action)
It's all in the developer docs!
So to use this:
first build your action with the NotificationCompat.Action.Builder
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_prev, "Previous", prevPendingIntent).build();
Note: Use NotificationCompat.Action
And than add it to your notification:
yournotification.addAction(action);
Use Icon
class at first parameter for Drawable if api level >= 23(marshmallow)
https://developer.android.com/reference/android/app/Notification.Action.Builder.html
https://developer.android.com/sdk/api_diff/23/changes/android.app.Notification.Action.Builder.html
example)
Notification.Action action = new Notification.Action.Builder(
Icon.createWithResource(this, R.drawable.ic_prev),
"action string",
pendingIntent).build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With