本文整理汇总了Java中android.app.Notification.MediaStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Notification.MediaStyle方法的具体用法?Java Notification.MediaStyle怎么用?Java Notification.MediaStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.MediaStyle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNotification
import android.app.Notification; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private void buildNotification(String cmd) {
// Set style
Notification.MediaStyle style = new Notification.MediaStyle();
style.setMediaSession(mediaSession.getSessionToken());
// Setup intent and notification
Intent intent = new Intent(getApplicationContext(), PlayMediaService.class);
intent.putExtra(MUSIC_STOP, 0);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_headphone)
.setContentTitle(songData.getSongName())
.setContentText(songData.getSongArtist())
.setDeleteIntent(pendingIntent)
.setStyle(style);
// Add actions
builder.addAction(createAction(R.drawable.ic_prev_noti, "Previous", MUSIC_PREV));
if (cmd.equals(MUSIC_PLAY)) {
builder.addAction(createAction(R.drawable.ic_play_noti, "Play", MUSIC_PLAY));
}
if (cmd.equals(MUSIC_PAUSE)) {
builder.addAction(createAction(R.drawable.ic_pause_noti, "Pause", MUSIC_PAUSE));
}
builder.addAction(createAction(R.drawable.ic_next_noti, "Next", MUSIC_NEXT));
// Notify
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(1, builder.build());
}
示例2: buildNotification
import android.app.Notification; //导入方法依赖的package包/类
private Notification buildNotification() {
final String albumName = getAlbumName();
final String artistName = getArtistName();
final boolean isPlaying = isPlaying();
String text = TextUtils.isEmpty(albumName)
? artistName : artistName + " - " + albumName;
int playButtonResId = isPlaying
? R.drawable.ic_pause_black_36dp : R.drawable.ic_play_arrow_black_36dp;
int playButtonTitleResId = isPlaying
? R.string.notification_pause : R.string.notification_play;
Notification.MediaStyle style = new Notification.MediaStyle()
.setMediaSession(mSession.getSessionToken())
.setShowActionsInCompactView(0, 1, 2);
Intent nowPlayingIntent = new Intent("com.koma.music.notification.AUDIO_PLAYER")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent, 0);
Bitmap artwork;
artwork = ImageLoader.getInstance().loadImageSync(Utils.getAlbumArtUri(getAlbumId()).toString());
if (artwork == null) {
artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_album);
}
if (mNotificationPostTime == 0) {
mNotificationPostTime = System.currentTimeMillis();
}
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(artwork)
.setContentIntent(clickIntent)
.setContentTitle(getTrackName())
.setContentText(text)
.setWhen(mNotificationPostTime)
.setShowWhen(false)
.setStyle(style)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.addAction(R.drawable.ic_previous_notification,
getString(R.string.notification_prev),
retrievePlaybackAction(MusicServiceConstants.PREVIOUS_ACTION))
.addAction(playButtonResId, getString(playButtonTitleResId),
retrievePlaybackAction(MusicServiceConstants.TOGGLEPAUSE_ACTION))
.addAction(R.drawable.ic_next_notification,
getString(R.string.notification_next),
retrievePlaybackAction(MusicServiceConstants.NEXT_ACTION));
if (artwork != null) {
// builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
builder.setColor(Palette.from(artwork).generate().getMutedColor(
getResources().getColor(R.color.colorPrimary)));
}
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
return builder.build();
}