无法在通知中使用MediaStyle

时间:2018-12-10 12:14:46

标签: android notifications

我想创建一个带有音乐控制按钮的音乐通知。并且我读过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()添加到我的项目中。 我尝试过的:

  1. 将此行添加到依赖项:

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

但这会导致此错误

  

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

0 个答案:

没有答案