community-cordova-plugin-social-sharing 6.2.0 → 6.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -10
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/nl/xservices/plugins/SocialSharing.java +173 -74
package/README.md
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
# PhoneGap / Cordova Social Sharing plugin
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/community-cordova-plugin-social-sharing)
|
|
4
|
+
[](https://www.npmjs.com/package/community-cordova-plugin-social-sharing)
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
#### This is a fork of the original plugin cordova-plugin-x-socialsharing
|
|
9
9
|
|
|
10
|
+
I dedicate a considerable amount of my free time to developing and maintaining many cordova plugins for the community ([See the list with all my maintained plugins][community_plugins]).
|
|
11
|
+
To help ensure this plugin is kept updated,
|
|
12
|
+
new features are added and bugfixes are implemented quickly,
|
|
13
|
+
please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance.
|
|
14
|
+
Please consider donating if you're using this plugin in an app that makes you money,
|
|
15
|
+
or if you're asking for new features or priority bug fixes. Thank you!
|
|
16
|
+
|
|
17
|
+
[](https://github.com/sponsors/eyalin)
|
|
18
|
+
|
|
10
19
|
|
|
11
|
-
[npm-image]:http://img.shields.io/npm/v/cordova-plugin-x-socialsharing.svg
|
|
12
|
-
[npm-url]:https://npmjs.org/package/cordova-plugin-x-socialsharing
|
|
13
|
-
[downloads-image]:http://img.shields.io/npm/dm/cordova-plugin-x-socialsharing.svg
|
|
14
|
-
[total-downloads-image]:http://img.shields.io/npm/dt/cordova-plugin-x-socialsharing.svg?label=total%20downloads
|
|
15
|
-
[twitter-image]:https://img.shields.io/twitter/follow/eddyverbruggen.svg?style=social&label=Follow%20me
|
|
16
|
-
[twitter-url]:https://twitter.com/eddyverbruggen
|
|
17
20
|
|
|
18
|
-
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=eddyverbruggen%40gmail%2ecom&lc=US&item_name=cordova%2dplugin%2dsocialsharing¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted)
|
|
19
|
-
Every now and then kind folks ask me how they can give me all their money. So if you want to contribute to my pension fund, then please go ahead :)
|
|
20
21
|
|
|
21
22
|
> Version 6.0.0 is compatible with Android X. See [this issue](https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/pull/1039) for details. 5.6.8 is the last version before 6.0.0, so be sure to pick that if you run into Android X-related issues.
|
|
22
23
|
|
|
@@ -580,3 +581,5 @@ https://developer.android.com/about/versions/11/privacy/package-visibility
|
|
|
580
581
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
|
581
582
|
</edit-config>
|
|
582
583
|
```
|
|
584
|
+
|
|
585
|
+
[community_plugins]: https://github.com/EYALIN?tab=repositories&q=community&type=&language=&sort=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "community-cordova-plugin-social-sharing",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
4
4
|
"description": "Share text, images (and other files), or a link via the native sharing widget of your device. Android is fully supported, as well as iOS 6 and up. WP8 has somewhat limited support.",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "community-cordova-plugin-social-sharing",
|
package/plugin.xml
CHANGED
|
@@ -39,6 +39,7 @@ import java.util.Timer;
|
|
|
39
39
|
import java.util.TimerTask;
|
|
40
40
|
import java.util.regex.Matcher;
|
|
41
41
|
import java.util.regex.Pattern;
|
|
42
|
+
import android.os.Bundle;
|
|
42
43
|
|
|
43
44
|
public class SocialSharing extends CordovaPlugin {
|
|
44
45
|
|
|
@@ -131,85 +132,183 @@ public class SocialSharing extends CordovaPlugin {
|
|
|
131
132
|
return cordova.getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 0;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
|
|
135
|
+
private boolean invokeEmailIntent(final CallbackContext callbackContext,
|
|
136
|
+
final String message,
|
|
137
|
+
final String subject,
|
|
138
|
+
final JSONArray to,
|
|
139
|
+
final JSONArray cc,
|
|
140
|
+
final JSONArray bcc,
|
|
141
|
+
final JSONArray files) throws JSONException {
|
|
142
|
+
final SocialSharing plugin = this;
|
|
143
|
+
Log.d("SocialSharing", "invokeEmailIntent called");
|
|
144
|
+
|
|
145
|
+
cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) {
|
|
146
|
+
public void run() {
|
|
147
|
+
Log.d("SocialSharing", "Runnable started");
|
|
148
|
+
|
|
149
|
+
boolean hasAttachments = files != null && files.length() > 0;
|
|
150
|
+
boolean hasMultipleFiles = files != null && files.length() > 1;
|
|
151
|
+
Log.d("SocialSharing", "Attachment count = " + (files != null ? files.length() : 0) +
|
|
152
|
+
", multiple? " + hasMultipleFiles);
|
|
153
|
+
|
|
154
|
+
// start with a generic intent
|
|
155
|
+
Intent draft = new Intent();
|
|
156
|
+
Log.d("SocialSharing", "Created base Intent");
|
|
157
|
+
|
|
158
|
+
// handle message
|
|
159
|
+
if (notEmpty(message)) {
|
|
160
|
+
Log.d("SocialSharing", "Message is not empty");
|
|
161
|
+
Pattern htmlPattern = Pattern.compile(".*\\<[^>]+>.*", Pattern.DOTALL);
|
|
162
|
+
|
|
163
|
+
if (hasMultipleFiles) {
|
|
164
|
+
ArrayList<CharSequence> texts = new ArrayList<>();
|
|
165
|
+
if (htmlPattern.matcher(message).matches()) {
|
|
166
|
+
Log.d("SocialSharing", "Message is HTML (multiple files)");
|
|
167
|
+
texts.add(Html.fromHtml(message));
|
|
168
|
+
draft.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, texts);
|
|
169
|
+
draft.setType("text/html");
|
|
170
|
+
} else {
|
|
171
|
+
Log.d("SocialSharing", "Message is plain text (multiple files)");
|
|
172
|
+
texts.add(message);
|
|
173
|
+
draft.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, texts);
|
|
174
|
+
draft.setType("text/plain");
|
|
175
|
+
}
|
|
176
|
+
Log.d("SocialSharing", "Added EXTRA_TEXT as ArrayList, size=" + texts.size());
|
|
177
|
+
} else {
|
|
178
|
+
if (htmlPattern.matcher(message).matches()) {
|
|
179
|
+
Log.d("SocialSharing", "Message is HTML (single/no file)");
|
|
180
|
+
draft.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(message));
|
|
181
|
+
draft.setType("text/html");
|
|
182
|
+
} else {
|
|
183
|
+
Log.d("SocialSharing", "Message is plain text (single/no file)");
|
|
184
|
+
draft.putExtra(Intent.EXTRA_TEXT, message);
|
|
185
|
+
draft.setType("text/plain");
|
|
186
|
+
}
|
|
187
|
+
Log.d("SocialSharing", "Added EXTRA_TEXT as String/CharSequence");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (notEmpty(subject)) {
|
|
192
|
+
Log.d("SocialSharing", "Subject added: " + subject);
|
|
193
|
+
draft.putExtra(Intent.EXTRA_SUBJECT, subject);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
if (to != null && to.length() > 0) {
|
|
198
|
+
Log.d("SocialSharing", "Adding TO addresses, count=" + to.length());
|
|
199
|
+
draft.putExtra(Intent.EXTRA_EMAIL, toStringArray(to));
|
|
200
|
+
}
|
|
201
|
+
if (cc != null && cc.length() > 0) {
|
|
202
|
+
Log.d("SocialSharing", "Adding CC addresses, count=" + cc.length());
|
|
203
|
+
draft.putExtra(Intent.EXTRA_CC, toStringArray(cc));
|
|
204
|
+
}
|
|
205
|
+
if (bcc != null && bcc.length() > 0) {
|
|
206
|
+
Log.d("SocialSharing", "Adding BCC addresses, count=" + bcc.length());
|
|
207
|
+
draft.putExtra(Intent.EXTRA_BCC, toStringArray(bcc));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (hasAttachments) {
|
|
211
|
+
Log.d("SocialSharing", "Processing attached files, count=" + files.length());
|
|
212
|
+
final String dir = getDownloadDir();
|
|
213
|
+
Log.d("SocialSharing", "Download dir = " + dir);
|
|
214
|
+
if (dir != null) {
|
|
215
|
+
ArrayList<Uri> fileUris = new ArrayList<>();
|
|
216
|
+
for (int i = 0; i < files.length(); i++) {
|
|
217
|
+
Log.d("SocialSharing", "Processing file index " + i + " : " + files.getString(i));
|
|
218
|
+
Uri fileUri = getFileUriAndSetType(draft, dir, files.getString(i), subject, i);
|
|
219
|
+
Log.d("SocialSharing", "Got fileUri: " + fileUri);
|
|
220
|
+
fileUri = FileProvider.getUriForFile(
|
|
221
|
+
webView.getContext(),
|
|
222
|
+
cordova.getActivity().getPackageName() + ".sharing.provider",
|
|
223
|
+
new File(fileUri.getPath())
|
|
224
|
+
);
|
|
225
|
+
Log.d("SocialSharing", "FileProvider URI: " + fileUri);
|
|
226
|
+
if (fileUri != null) {
|
|
227
|
+
fileUris.add(fileUri);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!fileUris.isEmpty()) {
|
|
231
|
+
Log.d("SocialSharing", "Adding " + fileUris.size() + " file URIs");
|
|
232
|
+
draft.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} catch (Exception e) {
|
|
237
|
+
Log.e("SocialSharing", "Exception during extras: " + Log.getStackTraceString(e));
|
|
238
|
+
callbackContext.error(e.getMessage());
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
draft.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
243
|
+
Log.d("SocialSharing", "FLAG_ACTIVITY_NEW_TASK added");
|
|
244
|
+
|
|
245
|
+
// set action
|
|
246
|
+
if (hasMultipleFiles) {
|
|
247
|
+
draft.setAction(Intent.ACTION_SEND_MULTIPLE);
|
|
248
|
+
Log.d("SocialSharing", "Set action: ACTION_SEND_MULTIPLE");
|
|
249
|
+
} else if (hasAttachments) {
|
|
250
|
+
draft.setAction(Intent.ACTION_SEND);
|
|
251
|
+
Log.d("SocialSharing", "Set action: ACTION_SEND");
|
|
252
|
+
} else {
|
|
253
|
+
draft.setAction(Intent.ACTION_SENDTO);
|
|
254
|
+
draft.setData(Uri.parse("mailto:"));
|
|
255
|
+
Log.d("SocialSharing", "Set action: ACTION_SENDTO with mailto:");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// query email apps
|
|
259
|
+
List<ResolveInfo> emailAppList = cordova.getActivity().getPackageManager().queryIntentActivities(draft, 0);
|
|
260
|
+
Log.d("SocialSharing", "Found email apps: " + emailAppList.size());
|
|
261
|
+
|
|
262
|
+
List<Intent> intentList = new ArrayList<>();
|
|
263
|
+
for (ResolveInfo info : emailAppList) {
|
|
264
|
+
Intent targeted = new Intent(draft);
|
|
265
|
+
targeted.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
|
|
266
|
+
intentList.add(targeted);
|
|
267
|
+
|
|
268
|
+
Log.d("SocialSharing", "Added Intent for " + info.activityInfo.packageName
|
|
269
|
+
+ " with action=" + targeted.getAction()
|
|
270
|
+
+ " extras=" + targeted.getExtras());
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!intentList.isEmpty()) {
|
|
274
|
+
Log.d("SocialSharing", "Creating chooser with " + intentList.size() + " intents");
|
|
275
|
+
|
|
276
|
+
Intent baseIntent = intentList.remove(intentList.size() - 1);
|
|
277
|
+
Intent[] extraIntents = intentList.toArray(new Intent[0]);
|
|
278
|
+
|
|
279
|
+
final Intent emailAppLists = Intent.createChooser(baseIntent, "Choose Email App");
|
|
280
|
+
emailAppLists.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
|
|
281
|
+
|
|
282
|
+
// dump extras for debug
|
|
283
|
+
Bundle extras = draft.getExtras();
|
|
284
|
+
if (extras != null) {
|
|
285
|
+
for (String key : extras.keySet()) {
|
|
286
|
+
Object value = extras.get(key);
|
|
287
|
+
Log.d("SocialSharing", "Final Intent extra: " + key + " = " + value +
|
|
288
|
+
" (" + (value != null ? value.getClass() : "null") + ")");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
cordova.getActivity().runOnUiThread(new Runnable() {
|
|
293
|
+
public void run() {
|
|
294
|
+
Log.d("SocialSharing", "Starting chooser activity");
|
|
295
|
+
cordova.startActivityForResult(plugin, emailAppLists, ACTIVITY_CODE_SENDVIAEMAIL);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
Log.e("SocialSharing", "No email apps found");
|
|
300
|
+
callbackContext.error("No email apps available");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
135
307
|
|
|
136
|
-
final SocialSharing plugin = this;
|
|
137
|
-
cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) {
|
|
138
|
-
public void run() {
|
|
139
|
-
Intent draft = new Intent(Intent.ACTION_SENDTO);
|
|
140
|
-
if (notEmpty(message)) {
|
|
141
|
-
Pattern htmlPattern = Pattern.compile(".*\\<[^>]+>.*", Pattern.DOTALL);
|
|
142
|
-
if (htmlPattern.matcher(message).matches()) {
|
|
143
|
-
draft.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(message));
|
|
144
|
-
draft.setType("text/html");
|
|
145
|
-
} else {
|
|
146
|
-
draft.putExtra(android.content.Intent.EXTRA_TEXT, message);
|
|
147
|
-
draft.setType("text/plain");
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (notEmpty(subject)) {
|
|
151
|
-
draft.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
if (to != null && to.length() > 0) {
|
|
155
|
-
draft.putExtra(android.content.Intent.EXTRA_EMAIL, toStringArray(to));
|
|
156
|
-
}
|
|
157
|
-
if (cc != null && cc.length() > 0) {
|
|
158
|
-
draft.putExtra(android.content.Intent.EXTRA_CC, toStringArray(cc));
|
|
159
|
-
}
|
|
160
|
-
if (bcc != null && bcc.length() > 0) {
|
|
161
|
-
draft.putExtra(android.content.Intent.EXTRA_BCC, toStringArray(bcc));
|
|
162
|
-
}
|
|
163
|
-
if (files.length() > 0) {
|
|
164
|
-
final String dir = getDownloadDir();
|
|
165
|
-
if (dir != null) {
|
|
166
|
-
ArrayList<Uri> fileUris = new ArrayList<Uri>();
|
|
167
|
-
for (int i = 0; i < files.length(); i++) {
|
|
168
|
-
Uri fileUri = getFileUriAndSetType(draft, dir, files.getString(i), subject, i);
|
|
169
|
-
fileUri = FileProvider.getUriForFile(webView.getContext(), cordova.getActivity().getPackageName()+".sharing.provider", new File(fileUri.getPath()));
|
|
170
|
-
if (fileUri != null) {
|
|
171
|
-
fileUris.add(fileUri);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (!fileUris.isEmpty()) {
|
|
175
|
-
draft.putExtra(Intent.EXTRA_STREAM, fileUris);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
} catch (Exception e) {
|
|
180
|
-
callbackContext.error(e.getMessage());
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// this was added to start the intent in a new window as suggested in #300 to prevent crashes upon return
|
|
185
|
-
draft.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
186
|
-
|
|
187
|
-
draft.setData(Uri.parse("mailto:"));
|
|
188
308
|
|
|
189
|
-
List<ResolveInfo> emailAppList = cordova.getActivity().getPackageManager().queryIntentActivities(draft, 0);
|
|
190
309
|
|
|
191
|
-
List<LabeledIntent> labeledIntentList = new ArrayList();
|
|
192
|
-
for (ResolveInfo info : emailAppList) {
|
|
193
|
-
draft.setAction(Intent.ACTION_SEND_MULTIPLE);
|
|
194
|
-
draft.setType("application/octet-stream");
|
|
195
310
|
|
|
196
|
-
draft.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
|
|
197
|
-
labeledIntentList.add(new LabeledIntent(draft, info.activityInfo.packageName, info.loadLabel(cordova.getActivity().getPackageManager()), info.icon));
|
|
198
|
-
}
|
|
199
|
-
final Intent emailAppLists = Intent.createChooser(labeledIntentList.remove(labeledIntentList.size() - 1), "Choose Email App");
|
|
200
|
-
emailAppLists.putExtra(Intent.EXTRA_INITIAL_INTENTS, labeledIntentList.toArray(new LabeledIntent[labeledIntentList.size()]));
|
|
201
311
|
|
|
202
|
-
// as an experiment for #300 we're explicitly running it on the ui thread here
|
|
203
|
-
cordova.getActivity().runOnUiThread(new Runnable() {
|
|
204
|
-
public void run() {
|
|
205
|
-
cordova.startActivityForResult(plugin, emailAppLists, ACTIVITY_CODE_SENDVIAEMAIL);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
312
|
|
|
214
313
|
private String getDownloadDir() throws IOException {
|
|
215
314
|
// better check, otherwise it may crash the app
|