【发布时间】:2015-08-24 00:02:23
【问题描述】:
我创建了一个自定义布局,我使用 RemoteView 将布局应用于我的通知。一切正常。
然后,我还想为我的通知实现 BigPictureStyle,这样当用户展开通知时,或者当它是第一个通知时,通知会变得更大,并且可以显示更多信息/更大的图标。
问题是:当通知展开时,我看不到自定义布局上的按钮(它在收缩时会显示)。
我的问题是:我的扩展通知如何具有相同的按钮?
这是我用来设置通知的代码:
Target mTarget;
String url = mMyTracks.get(mCurrentTrack).getCoverImgs();
Intent notificationIntent;
notificationIntent = new Intent(getApplicationContext(), TopTracksActivity.class);
notificationIntent.putParcelableArrayListExtra(MediaPlayerDialogFragment.TRACKS, mMyTracks);
notificationIntent.putExtra(MediaPlayerDialogFragment.TRACK_NUMBER, mCurrentTrack);
PendingIntent notificationPendingIntent =
PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.notification);
remoteView.setTextViewText(R.id.textSongName, track.getName());
remoteView.setTextViewText(R.id.textArtistName, track.getArtist());
// Create base notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_launcher)
.setContent(remoteView)
.setContentIntent(notificationPendingIntent);
//BigPicture notification style
final NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
bigPictureStyle.setBigContentTitle(track.getName());
bigPictureStyle.setSummaryText(track.getArtist());
mTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
bigPictureStyle.bigPicture(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
};
Picasso.with(getApplicationContext())
.load(url)
.into(mTarget);
// Build the notification
builder.setStyle(bigPictureStyle);
Notification notification = builder.build();
// Get current track's image
Picasso.with(getApplicationContext())
.load(url)
.into(remoteView, R.id.imageViewAlbumArt, 2503, notification);
startForeground(2503, notification);
谢谢! =]
【问题讨论】:
-
也许你想要这个? stackoverflow.com/a/13340548/706833 希望对您有所帮助;)
标签: android notifications android-notifications