本文整理汇总了Java中android.support.v4.media.session.MediaButtonReceiver.buildMediaButtonPendingIntent方法的典型用法代码示例。如果您正苦于以下问题:Java MediaButtonReceiver.buildMediaButtonPendingIntent方法的具体用法?Java MediaButtonReceiver.buildMediaButtonPendingIntent怎么用?Java MediaButtonReceiver.buildMediaButtonPendingIntent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaButtonReceiver
的用法示例。
在下文中一共展示了MediaButtonReceiver.buildMediaButtonPendingIntent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MediaNotificationManager
import android.support.v4.media.session.MediaButtonReceiver; //导入方法依赖的package包/类
public MediaNotificationManager(MusicService service) {
mService = service;
mNotificationManager =
(NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);
mPlayAction =
new NotificationCompat.Action(
R.drawable.ic_play_arrow_white_24dp,
mService.getString(R.string.label_play),
MediaButtonReceiver.buildMediaButtonPendingIntent(
mService,
PlaybackStateCompat.ACTION_PLAY));
mPauseAction =
new NotificationCompat.Action(
R.drawable.ic_pause_white_24dp,
mService.getString(R.string.label_pause),
MediaButtonReceiver.buildMediaButtonPendingIntent(
mService,
PlaybackStateCompat.ACTION_PAUSE));
mNextAction =
new NotificationCompat.Action(
R.drawable.ic_skip_next_white_24dp,
mService.getString(R.string.label_next),
MediaButtonReceiver.buildMediaButtonPendingIntent(
mService,
PlaybackStateCompat.ACTION_SKIP_TO_NEXT));
mPrevAction =
new NotificationCompat.Action(
R.drawable.ic_skip_previous_white_24dp,
mService.getString(R.string.label_previous),
MediaButtonReceiver.buildMediaButtonPendingIntent(
mService,
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS));
// Cancel all notifications to handle the case where the Service was killed and
// restarted by the system.
mNotificationManager.cancelAll();
}
示例2: buildNotification
import android.support.v4.media.session.MediaButtonReceiver; //导入方法依赖的package包/类
public static Notification buildNotification(Context context, MediaSessionCompat session) {
MediaControllerCompat controller = session.getController();
MediaMetadataCompat metadata = controller.getMetadata();
PlaybackStateCompat playbackState = controller.getPlaybackState();
if ((metadata == null) || (playbackState == null)) {
return null;
}
boolean isPlaying = playbackState.getState() == PlaybackStateCompat.STATE_PLAYING;
NotificationCompat.Action action = isPlaying ?
new NotificationCompat.Action(android.R.drawable.ic_media_pause,
context.getString(R.string.pause),
MediaButtonReceiver.buildMediaButtonPendingIntent(context,
PlaybackStateCompat.ACTION_PAUSE)) :
new NotificationCompat.Action(android.R.drawable.ic_media_play,
context.getString(R.string.play),
MediaButtonReceiver.buildMediaButtonPendingIntent(context,
PlaybackStateCompat.ACTION_PLAY));
MediaDescriptionCompat description = metadata.getDescription();
Bitmap albumArt = description.getIconBitmap();
if (albumArt == null) {
albumArt = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MusicService.NOTIFICATION_CHANNEL_ID);
builder.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
// .setShowActionsInCompactView(new int[]{0})
.setMediaSession(session.getSessionToken()))
.addAction(action)
.setSmallIcon(R.mipmap.ic_launcher)
.setShowWhen(false)
.setContentIntent(controller.getSessionActivity())
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setLargeIcon(albumArt)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder.build();
}