0

When building CustomTabsIntent using builder and setting setActionButton:

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

Crude implementation of getShareIntent:

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

I espect to get the extra's content in my Broadcast receiver. It works but when I rebuild it with different "someValue" I receive the initaial someValue.

Custom Tabs seem to only send the initial intent and ignore the updated intents until the Custom Tab Service is restarted.

The behaviour is not documented. Is it a bug?

1 Answers1

4

Here is the problem

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

2nd Parameter is the requestCode which should be different for different broadcast

Replace

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

with

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

Generate a different requestCode each time

Tabish Hussain
  • 852
  • 5
  • 13
  • Another option would be using the FLAG_UPDATE_CURRENT, to change the value of the extra. http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT – andreban Mar 15 '16 at 11:03