本文整理汇总了Java中android.support.v4.media.app.NotificationCompat.MediaStyle类的典型用法代码示例。如果您正苦于以下问题:Java MediaStyle类的具体用法?Java MediaStyle怎么用?Java MediaStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaStyle类属于android.support.v4.media.app.NotificationCompat包,在下文中一共展示了MediaStyle类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
public void buildNotification(Context context, final String albumName, final String artistName,
final String trackName, final Long albumId, final Bitmap albumArt,
final boolean isPlaying, MediaSessionCompat.Token mediaSessionToken) {
if (Utils.hasOreo()){
mNotificationManager.createNotificationChannel(AppNotificationChannels.getAudioChannel(context));
}
// Notification Builder
mNotificationBuilder = new NotificationCompat.Builder(mService, AppNotificationChannels.AUDIO_CHANNEL_ID)
.setShowWhen(false)
.setSmallIcon(R.drawable.itunes)
.setContentTitle(artistName)
.setContentText(trackName)
.setContentIntent(getOpenIntent(context))
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.cover))
.setPriority(Notification.PRIORITY_MAX)
.setStyle(new MediaStyle()
.setMediaSession(mediaSessionToken)
.setShowCancelButton(true)
.setShowActionsInCompactView(0, 1, 2)
.setCancelButtonIntent(retreivePlaybackActions(4)))
.addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_first, ""
, retreivePlaybackActions(3)))
.addAction(new android.support.v4.app.NotificationCompat.Action(isPlaying ? R.drawable.pause : R.drawable.play, ""
, retreivePlaybackActions(1)))
.addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_last, ""
, retreivePlaybackActions(2)));
mService.startForeground(APOLLO_MUSIC_SERVICE, mNotificationBuilder.build());
}
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:31,代码来源:NotificationHelper.java
示例2: getNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
private Notification getNotification(int playbackState) {
NotificationCompat.Builder builder = MediaStyleHelper.from(this, mediaSession);
builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_previous, getString(R.string.previous), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)));
if (playbackState == PlaybackStateCompat.STATE_PLAYING)
builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_pause, getString(R.string.pause), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
else
builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_play, getString(R.string.play), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_next, getString(R.string.next), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_NEXT)));
builder.setStyle(new MediaStyle()
.setShowActionsInCompactView(1)
.setShowCancelButton(true)
.setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_STOP))
.setMediaSession(mediaSession.getSessionToken())); // setMediaSession требуется для Android Wear
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); // The whole background (in MediaStyle), not just icon background
builder.setShowWhen(false);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setOnlyAlertOnce(true);
builder.setChannelId(NOTIFICATION_DEFAULT_CHANNEL_ID);
return builder.build();
}
开发者ID:SergeyVinyar,项目名称:AndroidAudioExample,代码行数:25,代码来源:PlayerService.java
示例3: buildPlayerNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.O)
public static Notification buildPlayerNotification(Context context, MediaSession mediaSession,
String title, String description, Bitmap largeIcon) {
PendingIntent openPartyIntent = PendingIntent.getActivity(context, 0,
new Intent(context, PartyActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Intent playPauseActionIntent = new Intent(context, SpotiqHostService.class);
playPauseActionIntent.setAction(ServiceConstants.ACTION_PLAY_PAUSE);
PendingIntent playPauseButtonIntent = PendingIntent.getForegroundService(context, 1,
playPauseActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
return new Notification.Builder(context, ApplicationConstants.MEDIA_NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_logo)
.setLargeIcon(largeIcon)
.setActions(new Notification.Action(R.drawable.ic_notification_play_pause, "Play/Pause", playPauseButtonIntent))
.setStyle(new Notification.MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowActionsInCompactView(0))
.setColorized(true)
.setContentTitle(title)
.setContentText(description)
.setContentIntent(openPartyIntent)
.setOngoing(true)
.build();
}
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:29,代码来源:NotificationUtil.java
示例4: buildPlayerNotificationCompat
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
public static Notification buildPlayerNotificationCompat(Context context, MediaSessionCompat mediaSessionCompat,
String title, String description, Bitmap largeIcon) {
PendingIntent openPartyIntent = PendingIntent.getActivity(context, 0,
new Intent(context, PartyActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Intent playPauseActionIntent = new Intent(context, SpotiqHostService.class);
playPauseActionIntent.setAction(ServiceConstants.ACTION_PLAY_PAUSE);
PendingIntent playPauseIntent = PendingIntent.getService(context, 1,
playPauseActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int largeIconWidth = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
int largeIconHeight = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
largeIcon = Bitmap.createScaledBitmap(largeIcon, largeIconWidth, largeIconHeight, false);
return new NotificationCompat.Builder(context, ApplicationConstants.MEDIA_NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_logo)
.setLargeIcon(largeIcon)
.addAction(new NotificationCompat.Action(R.drawable.ic_notification_play_pause, "Play/Pause", playPauseIntent))
.setStyle(new MediaStyle()
.setMediaSession(mediaSessionCompat.getSessionToken())
.setShowActionsInCompactView(0))
.setColorized(true)
.setContentTitle(title)
.setContentText(description)
.setContentIntent(openPartyIntent)
.setOngoing(true)
.setDefaults(4)
.build();
}
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:33,代码来源:NotificationUtil.java
示例5: notifyNowPlaying
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
/**
* Generate and post a notification for the current player status
* Posts the notification by starting the service in the foreground
*/
private void notifyNowPlaying() {
Timber.i("notifyNowPlaying called");
if (musicPlayer.getNowPlaying() == null) {
Timber.i("Not showing notification -- nothing is playing");
return;
}
MediaSessionCompat mediaSession = musicPlayer.getMediaSession();
if (mediaSession == null) {
Timber.i("Not showing notification. Media session is uninitialized");
return;
}
NotificationCompat.Builder builder =
MediaStyleHelper.from(this, mediaSession, NOTIFICATION_CHANNEL_ID);
setupNotificationActions(builder);
builder.setSmallIcon(getNotificationIcon())
.setDeleteIntent(getStopIntent())
.setStyle(
new MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setShowCancelButton(true)
.setCancelButtonIntent(getStopIntent())
.setMediaSession(musicPlayer.getMediaSession().getSessionToken()));
showNotification(builder.build());
}
开发者ID:marverenic,项目名称:Jockey,代码行数:35,代码来源:PlayerService.java
示例6: showIdleNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
/**
* Show idling notification
* @param game
*/
private void showIdleNotification(Game game) {
Log.i(TAG, "Idle notification");
final Intent notificationIntent = new Intent(this, MainActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.now_playing2, game.name))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentIntent(pendingIntent);
// MediaStyle causes a crash on certain Huawei devices running Lollipop
// https://stackoverflow.com/questions/34851943/couldnt-expand-remoteviews-mediasessioncompat-and-notificationcompat-mediastyl
if (!isHuawei) {
builder.setStyle(new MediaStyle());
}
if (game.dropsRemaining > 0) {
// Show drops remaining
builder.setSubText(getResources().getQuantityString(R.plurals.card_drops_remaining, game.dropsRemaining, game.dropsRemaining));
}
// Add the stop and pause actions
final PendingIntent stopIntent = PendingIntent.getBroadcast(this, 0, new Intent(STOP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT);
final PendingIntent pauseIntent = PendingIntent.getBroadcast(this, 0, new Intent(PAUSE_INTENT), PendingIntent.FLAG_CANCEL_CURRENT);
builder.addAction(R.drawable.ic_action_stop, getString(R.string.stop), stopIntent);
builder.addAction(R.drawable.ic_action_pause, getString(R.string.pause), pauseIntent);
if (farming) {
// Add the skip action
final PendingIntent skipIntent = PendingIntent.getBroadcast(this, 0, new Intent(SKIP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT);
builder.addAction(R.drawable.ic_action_skip, getString(R.string.skip), skipIntent);
}
final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (!PrefsManager.minimizeData()) {
// Load game icon into notification
Glide.with(getApplicationContext())
.load(game.iconUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
builder.setLargeIcon(resource);
nm.notify(NOTIF_ID, builder.build());
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
nm.notify(NOTIF_ID, builder.build());
}
});
} else {
nm.notify(NOTIF_ID, builder.build());
}
}
开发者ID:steevp,项目名称:UpdogFarmer,代码行数:64,代码来源:SteamService.java
示例7: buildNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
private NotificationCompat.Builder buildNotification(@NonNull PlaybackStateCompat state,
MediaSessionCompat.Token token,
boolean isPlaying,
MediaDescriptionCompat description) {
// Create the (mandatory) notification channel when running on Android Oreo.
if (isAndroidOOrHigher()) {
createChannel();
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(mService, CHANNEL_ID);
builder.setStyle(
new MediaStyle()
.setMediaSession(token)
.setShowActionsInCompactView(0, 1, 2)
// For backwards compatibility with Android L and earlier.
.setShowCancelButton(true)
.setCancelButtonIntent(
MediaButtonReceiver.buildMediaButtonPendingIntent(
mService,
PlaybackStateCompat.ACTION_STOP)))
.setColor(ContextCompat.getColor(mService, R.color.notification_bg))
.setSmallIcon(R.drawable.ic_stat_image_audiotrack)
// Pending intent that is fired when user clicks on notification.
.setContentIntent(createContentIntent())
// Title - Usually Song name.
.setContentTitle(description.getTitle())
// Subtitle - Usually Artist name.
.setContentText(description.getSubtitle())
.setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
// When notification is deleted (when playback is paused and notification can be
// deleted) fire MediaButtonPendingIntent with ACTION_STOP.
.setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(
mService, PlaybackStateCompat.ACTION_STOP))
// Show controls on lock screen even when user hides sensitive content.
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
// If skip to next action is enabled.
if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
builder.addAction(mPrevAction);
}
builder.addAction(isPlaying ? mPauseAction : mPlayAction);
// If skip to prev action is enabled.
if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
builder.addAction(mNextAction);
}
return builder;
}
开发者ID:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:52,代码来源:MediaNotificationManager.java
示例8: buildNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
private NotificationCompat.Builder buildNotification(@NonNull PlaybackStateCompat state,
MediaSessionCompat.Token token,
boolean isPlaying,
MediaDescriptionCompat description) {
// Create the (mandatory) notification channel when running on Android Oreo.
if (isAndroidOOrHigher()) {
createChannel();
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(mService, CHANNEL_ID);
builder.setStyle(
new MediaStyle()
.setMediaSession(token)
.setShowActionsInCompactView(0, 1, 2)
// For backwards compatibility with Android L and earlier.
.setShowCancelButton(true)
.setCancelButtonIntent(
MediaButtonReceiver.buildMediaButtonPendingIntent(
mService,
PlaybackStateCompat.ACTION_STOP)))
.setColor(ContextCompat.getColor(mService, R.color.notification_bg))
.setSmallIcon(R.drawable.ic_stat_image_audiotrack)
// Pending intent that is fired when user clicks on notification.
.setContentIntent(createContentIntent())
// Title - Usually Song name.
.setContentTitle(description.getTitle())
// Subtitle - Usually Artist name.
.setContentText(description.getSubtitle())
.setLargeIcon(LocalMusicLibrary.getAlbumBitmap(description.getMediaId()))
// When notification is deleted (when playback is paused and notification can be
// deleted) fire MediaButtonPendingIntent with ACTION_STOP.
.setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(
mService, PlaybackStateCompat.ACTION_STOP))
// Show controls on lock screen even when user hides sensitive content.
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
// If skip to next action is enabled.
if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
builder.addAction(mPrevAction);
}
builder.addAction(isPlaying ? mPauseAction : mPlayAction);
// If skip to prev action is enabled.
if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
builder.addAction(mNextAction);
}
return builder;
}
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:52,代码来源:MediaNotificationManager.java
示例9: createNotification
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
private Notification createNotification() {
LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
if (mMetadata == null || mPlaybackState == null) {
return null;
}
MediaDescriptionCompat description = mMetadata.getDescription();
String fetchArtUrl = null;
Bitmap art = null;
if (description.getIconUri() != null) {
// This sample assumes the iconUri will be a valid URL formatted String, but
// it can actually be any valid Android Uri formatted String.
// async fetch the album art icon
String artUrl = description.getIconUri().toString();
art = AlbumArtCache.getInstance().getBigImage(artUrl);
if (art == null) {
fetchArtUrl = artUrl;
// use a placeholder art while the remote art is being downloaded
art = BitmapFactory.decodeResource(mService.getResources(),
R.drawable.ic_default_art);
}
}
// Notification channels are only supported on Android O+.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel();
}
final NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(mService, CHANNEL_ID);
final int playPauseButtonPosition = addActions(notificationBuilder);
notificationBuilder
.setStyle(new MediaStyle()
// show only play/pause in compact view
.setShowActionsInCompactView(playPauseButtonPosition)
.setShowCancelButton(true)
.setCancelButtonIntent(mStopIntent)
.setMediaSession(mSessionToken))
.setDeleteIntent(mStopIntent)
.setColor(mNotificationColor)
.setSmallIcon(R.drawable.ic_notification)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setOnlyAlertOnce(true)
.setContentIntent(createContentIntent(description))
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setLargeIcon(art);
if (mController != null && mController.getExtras() != null) {
String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
if (castName != null) {
String castInfo = mService.getResources()
.getString(R.string.casting_to_device, castName);
notificationBuilder.setSubText(castInfo);
notificationBuilder.addAction(R.drawable.ic_close_black_24dp,
mService.getString(R.string.stop_casting), mStopCastIntent);
}
}
setNotificationPlaybackState(notificationBuilder);
if (fetchArtUrl != null) {
fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
}
return notificationBuilder.build();
}
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:69,代码来源:MediaNotificationManager.java
示例10: update
import android.support.v4.media.app.NotificationCompat.MediaStyle; //导入依赖的package包/类
@Override
public synchronized void update() {
stopped = false;
final Song song = service.getCurrentSong();
final String albumName = song.albumName;
final String artistName = song.artistName;
final boolean isPlaying = service.isPlaying();
final String text = TextUtils.isEmpty(albumName)
? artistName : artistName + " - " + albumName;
final int playButtonResId = isPlaying
? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
Intent action = new Intent(service, MainActivity.class);
action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
final PendingIntent clickIntent = PendingIntent.getActivity(service, 0, action, 0);
final ComponentName serviceName = new ComponentName(service, MusicService.class);
Intent intent = new Intent(MusicService.ACTION_QUIT);
intent.setComponent(serviceName);
final PendingIntent deleteIntent = PendingIntent.getService(service, 0, intent, 0);
final int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
service.runOnUiThread(() -> SongGlideRequest.Builder.from(Glide.with(service), song)
.checkIgnoreMediaStore(service)
.generatePalette(service).build()
.into(new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {
@Override
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
Palette palette = resource.getPalette();
update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(Color.TRANSPARENT)));
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
update(null, Color.TRANSPARENT);
}
void update(Bitmap bitmap, int color) {
if (bitmap == null)
bitmap = BitmapFactory.decodeResource(service.getResources(), R.drawable.default_album_art);
NotificationCompat.Action playPauseAction = new NotificationCompat.Action(playButtonResId,
service.getString(R.string.action_play_pause),
retrievePlaybackAction(ACTION_TOGGLE_PAUSE));
NotificationCompat.Action previousAction = new NotificationCompat.Action(R.drawable.ic_skip_previous_white_24dp,
service.getString(R.string.action_previous),
retrievePlaybackAction(ACTION_REWIND));
NotificationCompat.Action nextAction = new NotificationCompat.Action(R.drawable.ic_skip_next_white_24dp,
service.getString(R.string.action_next),
retrievePlaybackAction(ACTION_SKIP));
NotificationCompat.Builder builder = new NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(bitmap)
.setContentIntent(clickIntent)
.setDeleteIntent(deleteIntent)
.setContentTitle(song.title)
.setContentText(text)
.setOngoing(isPlaying)
.setShowWhen(false)
.addAction(previousAction)
.addAction(playPauseAction)
.addAction(nextAction);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setStyle(new MediaStyle().setMediaSession(service.getMediaSession().getSessionToken()).setShowActionsInCompactView(0, 1, 2))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && PreferenceUtil.getInstance(service).coloredNotification())
builder.setColor(color);
}
if (stopped)
return; // notification has been stopped before loading was finished
updateNotifyModeAndPostNotification(builder.build());
}
}));
}
开发者ID:kabouzeid,项目名称:Phonograph,代码行数:79,代码来源:PlayingNotificationImpl24.java
注:本文中的android.support.v4.media.app.NotificationCompat.MediaStyle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论