我正在尝试在 Android 11 中显示媒体样式通知,因为现在这是拥有全彩色背景且无边框的唯一选择。除了在一台设备上显示“打开蓝牙”按钮或在另一台设备上显示“电话扬声器”外,一切正常。这是它的样子:
另外,这是我的代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), AppConstants.NOTIFICATION_CHANNEL_REMINDERS);
builder.setAutoCancel(false)
.setOnlyAlertOnce(true)
.setShowWhen(true)
.setColor(Color.TRANSPARENT)
.setColorized(false)
.setWhen(System.currentTimeMillis())
.setContent(finalExpandedView)
.setProgress(0, 0, false)
.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
.setShowCancelButton(true)
.setMediaSession(mediaSession[0].getSessionToken())
.setShowCancelButton(true)
.setShowActionsInCompactView(0, 1, 2, 3, 4))
.setContentTitle(title)
.setCategory(NotificationCompat.CATEGORY_WORKOUT)
.setLocalOnly(true)
.setContentText(body)
.setSmallIcon(R.drawable.ic_notification_icon)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
//.setExtras(extras)
.addAction(R.drawable.smiley_tracking_sad, "very_sad", PendingIntent.getService(getApplicationContext(), 0, verySadIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(R.drawable.smiley_tracking_very_sad, "sad", PendingIntent.getService(getApplicationContext(), 1, sadIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(R.drawable.smiley_tracking_neutral, "neutral", PendingIntent.getService(getApplicationContext(), 2, neutralIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(R.drawable.smiley_tracking_glad, "glad", PendingIntent.getService(getApplicationContext(), 3, gladIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(R.drawable.smiley_tracking_really_glad, "really_glad", PendingIntent.getService(getApplicationContext(), 4, veryGladIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(R.drawable.smiley_tracking_really_glad, "really_glad", PendingIntent.getService(getApplicationContext(), 4, veryGladIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.setPriority(NotificationCompat.PRIORITY_MIN);
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(1001, builder.build());
有谁知道为什么会显示这些不需要的操作?提前致谢!