diff options
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-x-socialsharing/src')
8 files changed, 119 insertions, 36 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 diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+URLEncoding.h b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+SSURLEncoding.h index d7da331d..71447b60 100644 --- a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+URLEncoding.h +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+SSURLEncoding.h @@ -1,5 +1,5 @@ #import <Foundation/Foundation.h> -@interface NSString (URLEncoding) +@interface NSString (SSURLEncoding) @property (readonly) NSString *URLEncodedString; @end diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+URLEncoding.m b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+SSURLEncoding.m index b737626c..c8e746d3 100644 --- a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+URLEncoding.m +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/NSString+SSURLEncoding.m @@ -1,6 +1,6 @@ -#import "NSString+URLEncoding.h" +#import "NSString+SSURLEncoding.h" -@implementation NSString (URLEncoding) +@implementation NSString (SSURLEncoding) - (NSString*)URLEncodedString { NSString* result = (NSString *)CFBridgingRelease( diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/SocialSharing.m b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/SocialSharing.m index 014925bd..57336cd9 100644 --- a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/SocialSharing.m +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/ios/SocialSharing.m @@ -1,5 +1,5 @@ #import "SocialSharing.h" -#import "NSString+URLEncoding.h" +#import "NSString+SSURLEncoding.h" #import <Cordova/CDV.h> #import <Social/Social.h> #import <Foundation/NSException.h> @@ -137,7 +137,7 @@ static NSString *const kShareOptionUrl = @"url"; #pragma GCC diagnostic ignored "-Wdeprecated-declarations" [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) { [self cleanupStoredFiles]; - NSDictionary * result = @{@"completed":@(completed), @"app":activityType}; + NSDictionary * result = @{@"completed":@(completed), @"app":activityType == nil ? @"" : activityType}; CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; @@ -361,21 +361,43 @@ static NSString *const kShareOptionUrl = @"url"; NSURL *file = [self getFile:path]; NSData* data = [fileManager contentsAtPath:file.path]; + if (!data) { + CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"invalid attachment"]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + return; + } + NSString* fileName; NSString* mimeType; NSString* basename = [self getBasenameFromAttachmentPath:path]; - if ([basename hasPrefix:@"data:"]) { - mimeType = (NSString*)[[[basename substringFromIndex:5] componentsSeparatedByString: @";"] objectAtIndex:0]; - fileName = @"attachment."; - fileName = [fileName stringByAppendingString:(NSString*)[[mimeType componentsSeparatedByString: @"/"] lastObject]]; - NSString *base64content = (NSString*)[[basename componentsSeparatedByString: @","] lastObject]; - data = [SocialSharing dataFromBase64String:base64content]; - } else { - fileName = [basename pathComponents].lastObject; - mimeType = [self getMimeTypeFromFileExtension:[basename pathExtension]]; - } - [self.globalMailComposer addAttachmentData:data mimeType:mimeType fileName:fileName]; + //Find data anywhere in string + NSRange rangeData = [basename rangeOfString:@"data:"]; + if (rangeData.location == NSNotFound) + { + fileName = [basename pathComponents].lastObject; + mimeType = [self getMimeTypeFromFileExtension:[basename pathExtension]]; + } + else + { + mimeType = (NSString*)[[[basename substringFromIndex:rangeData.location+rangeData.length] componentsSeparatedByString: @";"] objectAtIndex:0]; + + //Find df anywhere in string + NSRange rangeDF = [basename rangeOfString:@"df:"]; + //If not found fallback to default name + if (rangeDF.location == NSNotFound) { + fileName = @"attachment."; + fileName = [fileName stringByAppendingString:(NSString*)[[mimeType componentsSeparatedByString: @"/"] lastObject]]; + } else { + //Found, apply name + fileName = (NSString*)[[[basename substringFromIndex:rangeDF.location+rangeDF.length] componentsSeparatedByString: @";"] objectAtIndex:0]; + } + + + NSString *base64content = (NSString*)[[basename componentsSeparatedByString: @","] lastObject]; + data = [SocialSharing dataFromBase64String:base64content]; + } + [self.globalMailComposer addAttachmentData:data mimeType:mimeType fileName:fileName]; } } @@ -479,7 +501,7 @@ static NSString *const kShareOptionUrl = @"url"; _command = command; [self.commandDelegate runInBackground:^{ picker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; - [[self getTopMostViewController] presentViewController:picker animated:YES completion:nil]; + [[self getTopMostViewController] presentViewController:picker animated:NO completion:nil]; }]; } else { CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"not available"]; @@ -694,6 +716,7 @@ static NSString *const kShareOptionUrl = @"url"; -(NSURL*)getFile: (NSString *)fileName { NSURL *file = nil; if (fileName != (id)[NSNull null]) { + NSRange rangeData = [fileName rangeOfString:@"data:"]; if ([fileName hasPrefix:@"http"]) { NSURL *url = [NSURL URLWithString:fileName]; NSData *fileData = [NSData dataWithContentsOfURL:url]; @@ -706,14 +729,27 @@ static NSString *const kShareOptionUrl = @"url"; } else if ([fileName hasPrefix:@"file://"]) { // stripping the first 6 chars, because the path should start with / instead of file:// file = [NSURL fileURLWithPath:[fileName substringFromIndex:6]]; - } else if ([fileName hasPrefix:@"data:"]) { - // using a base64 encoded string - // extract some info from the 'fileName', which is for example: data:text/calendar;base64,<encoded stuff here> - NSString *fileType = (NSString*)[[[fileName substringFromIndex:5] componentsSeparatedByString: @";"] objectAtIndex:0]; - fileType = (NSString*)[[fileType componentsSeparatedByString: @"/"] lastObject]; - NSString *base64content = (NSString*)[[fileName componentsSeparatedByString: @","] lastObject]; - NSData *fileData = [SocialSharing dataFromBase64String:base64content]; - file = [NSURL fileURLWithPath:[self storeInFile:[NSString stringWithFormat:@"%@.%@", @"file", fileType] fileData:fileData]]; + } else if (rangeData.location != NSNotFound ){ + //If found "data:" + NSString *fileType = (NSString*)[[[fileName substringFromIndex:rangeData.location+rangeData.length] componentsSeparatedByString: @";"] objectAtIndex:0]; + + NSString* attachmentName; + //Find df anywhere in string + NSRange rangeDF = [fileName rangeOfString:@"df:"]; + //If not found fallback to default name + if (rangeDF.location == NSNotFound) { + attachmentName = @"attachment."; + attachmentName = [attachmentName stringByAppendingString:(NSString*)[[fileType componentsSeparatedByString: @"/"] lastObject]]; + } else { + //Found, apply name + attachmentName = (NSString*)[[[fileName substringFromIndex:rangeDF.location+rangeDF.length] componentsSeparatedByString: @";"] objectAtIndex:0]; + } + + + NSString *base64content = (NSString*)[[fileName componentsSeparatedByString: @","] lastObject]; + NSData* data = [SocialSharing dataFromBase64String:base64content]; + file = [NSURL fileURLWithPath:[self storeInFile:attachmentName fileData:data]]; + } else { // assume anywhere else, on the local filesystem file = [NSURL fileURLWithPath:fileName]; diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js index ff257d52..b52fa12f 100644 --- a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js @@ -1,4 +1,4 @@ -var cordova = require('cordova'); +var cordova = require('cordova'); module.exports = { share: function (win, fail, args) { @@ -10,7 +10,7 @@ module.exports = { var fileOrFileArray = args[2]; //Web link var url = args[3]; - + var folder = Windows.Storage.ApplicationData.current.temporaryFolder; var getExtension = function (strBase64) { @@ -49,7 +49,7 @@ module.exports = { var deferral = e.request.getDeferral(); var storageItems = []; var filesCount = fileOrFileArray.length; - + var completeFile = function () { if (!--filesCount) { storageItems.length && e.request.data.setStorageItems(storageItems); @@ -60,7 +60,7 @@ module.exports = { for (var i = 0; i < fileOrFileArray.length; i++) { var file = fileOrFileArray[i]; - if (file.indexOf("data:") >= 0) { + if (file.indexOf("data:") >= 0) { var fileName = getFileName(i, getExtension(file)); var buffer = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(file.split(',')[1]); if (buffer) { @@ -162,6 +162,15 @@ module.exports = { } catch (err) { fail(err); } + }, + + shareViaSMS: function (win, fail, args) { + var chatMessage = new Windows.ApplicationModel.Chat.ChatMessage(); + chatMessage.body = args[0].message; + if (!!args[1]) { + chatMessage.recipients.push(args[1]); + } + Windows.ApplicationModel.Chat.ChatMessageManager.showComposeSmsMessageAsync(chatMessage).done(win, fail); } }; diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/wp8/Newtonsoft.Json.dll b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/wp8/Newtonsoft.Json.dll Binary files differnew file mode 100755 index 00000000..b8194284 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/wp8/Newtonsoft.Json.dll |
