无法在通知中使用MediaStyle

我想通过一个控制音乐的按钮来创建音乐通知 . 我读了android developers guide,建议使用下面的代码来获得更好的UI .

Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
    // Show controls on lock screen even when user hides sensitive content.
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setSmallIcon(R.drawable.ic_stat_player)
    // Add media control buttons that invoke intents in your media service
    .addAction(R.drawable.ic_prev, "Previous", prevPendingIntent) // #0
    .addAction(R.drawable.ic_pause, "Pause", pausePendingIntent)  // #1
    .addAction(R.drawable.ic_next, "Next", nextPendingIntent)     // #2
    // Apply the media style template
    .setStyle(new android.support.v4.media.app.Notification.MediaStyle()
            .setShowActionsInCompactView(1 /* #1: pause button */)
            .setMediaSession(mMediaSession.getSessionToken()))
    .setContentTitle("Wonderful music")
    .setContentText("My Awesome Band")
    .setLargeIcon(albumArtBitmap)
    .build();

但是我无法将android.support.v4.media.app.Notification.MediaStyle()添加到我的项目中 . 我试过的:

  • 将此行添加到依赖项:

dependencies { implementation "com.android.support:support-compat:28.0.0" }

但它会导致此错误

无法解决:support-compat打开文件

回答(0)