diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-09-10 14:35:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-09-10 14:35:21 +0200 |
| commit | 3cf5e5a97afe8fc7877b528cf19130bef0d68bad (patch) | |
| tree | b2ba8044cb293716af3f3330903aea1d7b6bfcd9 /StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android | |
| parent | 50bf754c8742a5b7d054b9d93f9d4e37c1641a01 (diff) | |
build the app
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android')
3 files changed, 45 insertions, 7 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/FileProvider.java b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/FileProvider.java new file mode 100644 index 00000000..ef862604 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/FileProvider.java @@ -0,0 +1,5 @@ +package nl.xservices.plugins; + + +public class FileProvider extends android.support.v4.content.FileProvider { +}
\ No newline at end of file diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/SocialSharing.java b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/SocialSharing.java index 8de31da8..faa96ced 100644 --- a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/SocialSharing.java +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/nl/xservices/plugins/SocialSharing.java @@ -34,6 +34,8 @@ import java.util.TimerTask; import java.util.regex.Matcher; import java.util.regex.Pattern; +import nl.xservices.plugins.FileProvider; + public class SocialSharing extends CordovaPlugin { private static final String ACTION_AVAILABLE_EVENT = "available"; @@ -81,10 +83,10 @@ public class SocialSharing extends CordovaPlugin { } else if (ACTION_SHARE_VIA_TWITTER_EVENT.equals(action)) { return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "twitter", null, false, true); } else if (ACTION_SHARE_VIA_FACEBOOK_EVENT.equals(action)) { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", null, false, true); + return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", null, false, true, "com.facebook.composer.shareintent"); } else if (ACTION_SHARE_VIA_FACEBOOK_WITH_PASTEMESSAGEHINT.equals(action)) { this.pasteMessage = args.getString(4); - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", null, false, true); + return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", null, false, true, "com.facebook.composer.shareintent"); } else if (ACTION_SHARE_VIA_WHATSAPP_EVENT.equals(action)) { if (notEmpty(args.getString(4))) { return shareViaWhatsAppDirectly(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4)); @@ -169,6 +171,7 @@ public class SocialSharing extends CordovaPlugin { } } catch (Exception e) { callbackContext.error(e.getMessage()); + return; } // this was added to start the intent in a new window as suggested in #300 to prevent crashes upon return @@ -215,6 +218,19 @@ public class SocialSharing extends CordovaPlugin { } private boolean doSendIntent( + final CallbackContext callbackContext, + final String msg, + final String subject, + final JSONArray files, + final String url, + final String appPackageName, + final String chooserTitle, + final boolean peek, + final boolean boolResult) { + return doSendIntent(callbackContext, msg, subject, files, url, appPackageName, chooserTitle, peek, boolResult, null); + } + + private boolean doSendIntent( final CallbackContext callbackContext, final String msg, final String subject, @@ -223,7 +239,8 @@ public class SocialSharing extends CordovaPlugin { final String appPackageName, final String chooserTitle, final boolean peek, - final boolean boolResult) { + final boolean boolResult, + final String appName) { final CordovaInterface mycordova = cordova; final CordovaPlugin plugin = this; @@ -243,6 +260,7 @@ public class SocialSharing extends CordovaPlugin { Uri fileUri = null; for (int i = 0; i < files.length(); i++) { fileUri = getFileUriAndSetType(sendIntent, dir, files.getString(i), subject, i); + fileUri = FileProvider.getUriForFile(webView.getContext(), cordova.getActivity().getPackageName()+".sharing.provider", new File(fileUri.getPath())); if (fileUri != null) { fileUris.add(fileUri); } @@ -295,7 +313,7 @@ public class SocialSharing extends CordovaPlugin { packageName = items[0]; passedActivityName = items[1]; } - final ActivityInfo activity = getActivity(callbackContext, sendIntent, packageName); + final ActivityInfo activity = getActivity(callbackContext, sendIntent, packageName, appName); if (activity != null) { if (peek) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); @@ -369,6 +387,8 @@ public class SocialSharing extends CordovaPlugin { String localImage = image; if (image.endsWith("mp4") || image.endsWith("mov") || image.endsWith("3gp")){ sendIntent.setType("video/*"); + } else if (image.endsWith("mp3")) { + sendIntent.setType("audio/x-mpeg"); } else { sendIntent.setType("image/*"); } @@ -432,7 +452,7 @@ public class SocialSharing extends CordovaPlugin { final String encodedImg = image.substring(image.indexOf(";base64,") + 8); sendIntent.setType(fileType); saveFile(Base64.decode(encodedImg, Base64.DEFAULT), dir, sanitizeFilename(fileName)); - localImage = "file://" + dir + "/" + fileName; + localImage = "file://" + dir + "/" + sanitizeFilename(fileName); } else if (!image.startsWith("file://")) { throw new IllegalArgumentException("URL_NOT_SUPPORTED"); } else { @@ -649,12 +669,14 @@ public class SocialSharing extends CordovaPlugin { return null; } - private ActivityInfo getActivity(final CallbackContext callbackContext, final Intent shareIntent, final String appPackageName) { + private ActivityInfo getActivity(final CallbackContext callbackContext, final Intent shareIntent, final String appPackageName, final String appName) { final PackageManager pm = webView.getContext().getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { if ((app.activityInfo.packageName).contains(appPackageName)) { - return app.activityInfo; + if (appName == null || (app.activityInfo.name).contains(appName)) { + return app.activityInfo; + } } } // no matching app found diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/res/xml/sharing_paths.xml b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/res/xml/sharing_paths.xml new file mode 100644 index 00000000..278084a2 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/android/res/xml/sharing_paths.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<paths> + <external-path + name="Android/data/${applicationId}/socialsharing_downloads" + path="./socialsharing-downloads"/> + + <root-path + name="root" + path="/"/> + +</paths>
\ No newline at end of file |
