Bug 1337771 - Let ActionButton works in some apps
If the intent from 3rd-party app doesn't have data url, directly call
PendingIntent.send() will perform nothing. To use current url as
polyfill to fix it.
MozReview-Commit-ID: IIP7hGd1cBH
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -8,16 +8,17 @@ package org.mozilla.gecko.customtabs;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -265,17 +266,25 @@ public class CustomTabsActivity extends
final Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ColorUtil.darken(toolbarColor, 0.25));
}
}
+ private void performPendingIntent(@NonNull PendingIntent pendingIntent) {
+ // bug 1337771: If intent-creator haven't set data url, call send() directly won't work.
+ final Intent additional = new Intent();
+ final Tab tab = Tabs.getInstance().getSelectedTab();
+ additional.setData(Uri.parse(tab.getURL()));
+ try {
+ pendingIntent.send(this, 0, additional);
+ } catch (PendingIntent.CanceledException e) {
+ Log.w(LOGTAG, "Performing a canceled pending intent", e);
+ }
+ }
+
private void onActionButtonClicked() {
PendingIntent pendingIntent = IntentUtil.getActionButtonPendingIntent(getIntent());
- try {
- pendingIntent.send();
- } catch (PendingIntent.CanceledException e) {
- Log.w(LOGTAG, "Action Button clicked, but pending intent was canceled", e);
- }
+ performPendingIntent(pendingIntent);
}
}