0

使用 builder 构建 CustomTabsIntent 并设置 setActionButton 时:

new CustomTabsIntent.Builder(getSession())
            .setActionButton(getShareIcon(),
                             "Share text",
                             getShareIntent(),
                             true)
            .build()

getShareIntent 的粗略实现:

@NonNull
private PendingIntent getShareIntent() {
    Intent shareIntent = new Intent(mContext, ShareBroadcastReceiver.class);
    shareIntent.putExtra("extra", someValue);
    return PendingIntent.getBroadcast(mContext, 0, shareIntent, 0);
}

我希望在我的广播接收器中获得额外的内容。它可以工作,但是当我用不同的“someValue”重建它时,我收到了初始的 someValue。

自定义选项卡似乎只发送初始意图并忽略更新的意图,直到自定义选项卡服务重新启动。

该行为未记录在案。它是一个错误吗?

4

1 回答 1

4

这是问题

@NonNull
private PendingIntent getShareIntent() {
   Intent shareIntent = new Intent(mContext, ShareBroadcastReceiver.class);
   shareIntent.putExtra("extra", someValue);
   return PendingIntent.getBroadcast(mContext, 0, shareIntent, 0);
}

第二个参数是requestCode,对于不同的广播应该是不同的

代替

PendingIntent.getBroadcast(mContext, 0, shareIntent, 0);

PendingIntent.getBroadCast(mContext, requestCode , shareIntent, 0}

每次生成不同的requestCode

于 2016-03-14T13:22:30.480 回答