折叠通知时显示操作图标

Make Action icons appear when notification is collapsed

我目前添加了两个操作,它们在展开通知时显示为按钮。根据文档折叠通知时,它们不会出现。一些应用程序也会在通知折叠时显示按钮(请参阅下面的 Google 播放音乐)。如何让我的通知做到这一点?

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context)
                .setSmallIcon(R.drawable.notification_isplaying)
                .setContentTitle(nameOnly)
                .setContentText(contentText)
                .setAutoCancel(false).setWhen(0).setContentIntent(aIntent)
                .addAction(toDisplay, text, pIntent)
                .addAction(R.drawable.ic_stop_white_36dp, context.getResources().getString(R.string.stop), sIntent)
                .setPriority(Notification.PRIORITY_MAX);

您需要使用 I/O 2016 年的 MediaStyle notification and use setShowActionsInCompactView() to set which actions you want to appear in the compact, unexpanded view as explained in the Best practices in media playback talk