Android notification not showing more than 3 actions

左心房为你撑大大i 提交于 2019-12-01 17:22:51

问题


I want to display a notification with 5 actions, but it ony displays 3 of them. This is the code I'm using for displaying it

Notification notification =
            new android.support.v7.app.NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!")
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action1, null, pendingIntent1).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action2, null, pendingIntent2).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action3, null, pendingIntent3).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action4, null, pendingIntent4).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action5, null, pendingIntent5).build())
                    .setAutoCancel(false)
                    .build();

NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(MEETING_NOTIFICATION_ID, notification);

回答1:


you can only show max 3 actions as mentioned in the Notification.Builder addAction (Notification.Action action) too

A notification in its expanded form can display up to 3 actions, from left to right in the order they were added.

Alternatively you create custom RemoteViews and use setCustomContentView

Reference

Read Custom Notification Layouts

Adding button action in custom notification




回答2:


Notifications can only display 3 actions.

A notification in its expanded form can display up to 3 actions, from left to right in the order they were added.

Source, the offical Notification.Builder documentation: https://developer.android.com/reference/android/app/Notification.Builder.html#addAction(android.app.Notification.Action)

If you absolutely need more than 3 actions, you'll have to opt for a solution using a custom view to display in the notification.



来源:https://stackoverflow.com/questions/42534165/android-notification-not-showing-more-than-3-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!