【问题标题】:Normal notification applies RemoteView, but BigPictureStyle doesn't正常通知适用 RemoteView,但 BigPictureStyle 不适用
【发布时间】: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);

谢谢! =]

【问题讨论】:

标签: android notifications android-notifications


【解决方案1】:

虽然我无法找到 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多