带有 RemoteView 和操作的自定义 Android 通知

Custom Android notification with RemoteView and actions

我在使用 RemoteViews 显示通知并使用 addAction(R.drawable.ic_notification, "More", pendingIntent)

添加操作时遇到问题

这是没有 addAction 方法的 remoteViews 的通知

这是带有 addAction 的通知

如您所见,系统不显示 RemoteView,仅显示操作按钮

这是远程视图的实例

RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
notificationLayout.setImageViewResource(R.id.notification_small_iv, R.drawable.logo);
notificationLayout.setTextViewText(R.id.notification_small_title, remoteMessage.getData().get(TITLE));
notificationLayout.setTextViewText(R.id.notification_small_subtitle, remoteMessage.getData().get(CONTENT));

这是我设置配置并添加操作的通知生成器

Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setCustomContentView(notificationLayout)
            .setColor(getResources().getColor(R.color.nice_blue))
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .setLights(Color.BLUE, 1000, 1000)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setPriority(PRIORITY_MAX)
            .setDefaults(DEFAULT_ALL)
              .addAction( 0,"More", pendingIntent)
            .build();

这是我创建待定 Intent 的方式,但我不确定是否相关

PendingIntent pendingIntent;
Intent intent = new Intent(this, SplashActivity.class);
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

我很确定有一个自定义视图和一个 AddAction 按钮是可能的,因为 Slack 在 Android 应用程序中有它

我在同一条船上。我想要在顶部有一个自定义视图,在底部有操作按钮的选项。您正在寻找的是 NotificationCompat.DecoratedCustomViewStyle.