public static class PlayerService.MediaNotificationView extends PlayerService.NotificationView
该类是个抽象类,可以通过实现 onBuildMediaStyle(androidx.media.app.NotificationCompat.MediaStyle)
方法和实现 onBuildNotification(NotificationCompat.Builder)
来对当前 NotificationView
的外观进行定制。
更多信息,请参考官方文档: https://developer.android.google.cn/training/notify-user/expanded#media-style
CHANNEL_ID
构造器和说明 |
---|
MediaNotificationView() |
限定符和类型 | 方法和说明 |
---|---|
android.app.PendingIntent |
doPlayPause() |
android.app.PendingIntent |
doSkipToNext() |
android.app.PendingIntent |
doSkipToPrevious() |
int |
getNotificationId()
返回 Notification 的 ID。
|
int |
getSmallIconId()
Notification 的 small icon 的资源 id。
|
protected void |
onBuildMediaStyle(androidx.media.app.NotificationCompat.MediaStyle mediaStyle)
该方法会在创建
NotificationCompat.MediaStyle 对象期间调用。 |
protected void |
onBuildNotification(androidx.core.app.NotificationCompat.Builder builder)
该方法会在创建
NotificationCompat.Builder 期间调用。 |
android.app.Notification |
onCreateNotification()
创建一个新的 Notification 对象,不能为 null。
|
protected void |
onInit(android.content.Context context)
该方法会在初次创建 NotificationView 对象时调用,你可以重写该方法来进行一些初始化操作。
|
addCustomAction, buildCustomAction, getContentText, getContext, getDefaultIcon, getErrorMessage, getIcon, getMediaSession, getPackageName, getPlaybackState, getPlayingMusicItem, getPlaylistExtra, getPlayMode, invalidate, isError, isExpire, isPlayingState, isPrepared, isPreparing, isReleased, isStalled, onCreateBetterIconLoader, onCreateIconLoader, onPlayModeChanged, onRelease, setDefaultIcon, setIcon, setIconSize, setIconSize, shutdown
protected void onInit(android.content.Context context)
PlayerService.NotificationView
onInit
在类中 PlayerService.NotificationView
public final android.app.PendingIntent doSkipToPrevious()
public final android.app.PendingIntent doPlayPause()
public final android.app.PendingIntent doSkipToNext()
@NonNull public android.app.Notification onCreateNotification()
PlayerService.NotificationView
onCreateNotification
在类中 PlayerService.NotificationView
public int getNotificationId()
PlayerService.NotificationView
@DrawableRes public int getSmallIconId()
protected void onBuildMediaStyle(androidx.media.app.NotificationCompat.MediaStyle mediaStyle)
NotificationCompat.MediaStyle
对象期间调用。
可以在该方法中对 NotificationCompat.MediaStyle
对象进行配置。例如,调用
setShowActionsInCompactView (int... actions)
方法设置要在紧凑的通知视图中显示的操作。
protected void onBuildNotification(androidx.core.app.NotificationCompat.Builder builder)
NotificationCompat.Builder
期间调用。
可以在该方法中对 NotificationCompat.Builder
对象进行配置。例如,调用
addAction (int icon, CharSequence title, PendingIntent intent)
向通知添加操作。
该方法中使用 addAction 方法添加了三个按钮:上一曲、播放/暂停、下一曲。如果你不需要这三个按钮, 则你在覆盖该方法时可以不回调超类方法。