我遇到一个问题,该问题显示带有RemoteViews
的通知并使用addAction(R.drawable.ic_notification, "More", pendingIntent)
对其进行操作
这是不带addAction
方法的remoteViews通知
这是带有addAction的通知
如您所见,系统不显示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应用程序中拥有它