| Index: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
|
| index 97583b682427c1491325995f4a6fa8c3e7c6c11d..8b4151ed4360f90c8b1776d12bc3020d2b992ddf 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
|
| @@ -314,8 +314,11 @@ public class ShareHelper {
|
| * Trigger the share action for the given image data.
|
| * @param activity The activity used to trigger the share action.
|
| * @param jpegImageData The image data to be shared in jpeg format.
|
| + * @param name When this is not null, it will share the image directly with whatever the
|
| + * component name is.
|
| */
|
| - public static void shareImage(final Activity activity, final byte[] jpegImageData) {
|
| + public static void shareImage(
|
| + final Activity activity, final byte[] jpegImageData, final ComponentName name) {
|
| if (jpegImageData.length == 0) {
|
| Log.w(TAG, "Share failed -- Received image contains no data.");
|
| return;
|
| @@ -362,9 +365,15 @@ public class ShareHelper {
|
| Uri imageUri = ApiCompatibilityUtils.getUriForImageCaptureFile(activity,
|
| saveFile);
|
|
|
| - Intent chooserIntent = Intent.createChooser(getShareImageIntent(imageUri),
|
| - activity.getString(R.string.share_link_chooser_title));
|
| - fireIntent(activity, chooserIntent);
|
| + if (name == null) {
|
| + Intent chooserIntent = Intent.createChooser(getShareImageIntent(imageUri),
|
| + activity.getString(R.string.share_link_chooser_title));
|
| + fireIntent(activity, chooserIntent);
|
| + } else {
|
| + Intent imageIntent = getShareImageIntent(imageUri);
|
| + imageIntent.setComponent(name);
|
| + fireIntent(activity, imageIntent);
|
| + }
|
| }
|
| }
|
| }.execute();
|
| @@ -540,6 +549,26 @@ public class ShareHelper {
|
| * @param item The menu item that is used for direct share
|
| */
|
| public static void configureDirectShareMenuItem(Activity activity, MenuItem item) {
|
| + Drawable directShareIcon;
|
| + CharSequence directShareTitle;
|
| +
|
| + Pair<Drawable, CharSequence> directShare = getShareableIconAndName(activity);
|
| + directShareIcon = directShare.first;
|
| + directShareTitle = directShare.second;
|
| +
|
| + item.setIcon(directShareIcon);
|
| + if (directShareTitle != null) {
|
| + item.setTitle(
|
| + activity.getString(R.string.accessibility_menu_share_via, directShareTitle));
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Get the icon and name of the most recently shared app within chrome.
|
| + * @param activity Activity that is used to access the package manager.
|
| + * @return The Image and the String of the recently shared Icon.
|
| + */
|
| + public static Pair<Drawable, CharSequence> getShareableIconAndName(Activity activity) {
|
| Drawable directShareIcon = null;
|
| CharSequence directShareTitle = null;
|
|
|
| @@ -597,11 +626,7 @@ public class ShareHelper {
|
| "Android.IsLastSharedAppInfoRetrieved", retrieved);
|
| }
|
|
|
| - item.setIcon(directShareIcon);
|
| - if (directShareTitle != null) {
|
| - item.setTitle(activity.getString(R.string.accessibility_menu_share_via,
|
| - directShareTitle));
|
| - }
|
| + return new Pair<>(directShareIcon, directShareTitle);
|
| }
|
|
|
| /*
|
| @@ -674,7 +699,7 @@ public class ShareHelper {
|
| return intent;
|
| }
|
|
|
| - private static ComponentName getLastShareComponentName() {
|
| + public static ComponentName getLastShareComponentName() {
|
| SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
|
| String packageName = preferences.getString(PACKAGE_NAME_KEY, null);
|
| String className = preferences.getString(CLASS_NAME_KEY, null);
|
|
|