Android leanback notification intent 只获取上一部电影的数据

Android leanback notification intent only taking the data of last movie

在点击我的应用程序发送到我的 Android 电视的任何通知时,我只从最后添加的通知中获取数据,而不是我点击的通知。

我的代码:

for (Asset asset : assets) {
    ContentRecommendation.Builder builder = new ContentRecommendation.Builder()
            .setBadgeIcon(R.drawable.icon);
    int id = asset.getId().hashCode();

    Intent detailsIntent = new Intent(mContext, LoginActivity.class);
    Bundle bundle = new Bundle();
    bundle.putParcelable(mContext.getString(R.string.key_asset), asset);
    detailsIntent.putExtra(MainActivity.EXTRA_ASSET, bundle);
    detailsIntent.setAction(Intent.ACTION_VIEW);

    builder.setIdTag("Asset" + id)
        .setTitle(asset.getTitle())
        .setText(asset.getCast().replace(",", ", "))
        .setGenres(asset.getGenres().split(","))
        .setRunningTime(asset.getDuration())
        .setContentIntentData(ContentRecommendation.INTENT_TYPE_ACTIVITY,
                detailsIntent, 0, null)
        .setStatus(ContentRecommendation.CONTENT_STATUS_AVAILABLE)
        .setPricingInformation(ContentRecommendation.CONTENT_PRICING_SUBSCRIPTION, ".99")
        .setContentTypes(new String[]{ContentRecommendation.CONTENT_TYPE_MOVIE, ContentRecommendation.CONTENT_TYPE_SERIAL})
        .setContentImage(Picasso.with(mContext).load(asset.getThumbnailUrl()).get())
        .setProgress((int) (asset.getDuration() % 100000), (int) (asset.getPauseTime() % 100000))
        .setMaturityRating(asset.getRating());

    ContentRecommendation rec = builder.build();
    Notification notification = rec.getNotificationObject(mContext);
    mNotifManager.notify(id, notification);
}

是什么导致了这个错误,我该如何解决?

您必须为每个通知在 setContentIntentData 中传递不同的请求代码。

 .setContentIntentData(ContentRecommendation.INTENT_TYPE_ACTIVITY,
                detailsIntent, diff_value, null)