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

时间:2019-01-16 17:31:53

标签: android android-notifications

我遇到一个问题,该问题显示带有RemoteViews的通知并使用addAction(R.drawable.ic_notification, "More", pendingIntent)对其进行操作

这是不带addAction方法的remoteViews通知

enter image description here

这是带有addAction的通知

enter image description here

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

这是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应用程序中拥有它

1 个答案:

答案 0 :(得分:0)

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

Here is an example