正常通知适用于RemoteView,但BigPictureStyle不适用

时间:2015-08-24 00:02:23

标签: android notifications android-notifications

我创建了一个自定义布局,我使用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);

谢谢! =]

1 个答案:

答案 0 :(得分:0)

虽然我无法找到为什么BigPictureStyle不使用RemoteView(但是),但我找到了另一种解决方案:将动作设置为构建器。只有在扩展通知时才会显示此内容。

在我将样式设置为构建器之前,这是我添加到代码中的内容:

builder.addAction(R.drawable.ic_previous, "Previous", notificationPendingIntent);
builder.addAction(R.drawable.ic_pause, "Pause", notificationPendingIntent);
builder.addAction(R.drawable.ic_next, "Next", notificationPendingIntent);