From c77617f806ac422a5fbd7f936b669e598dba1a00 Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Wed, 12 Feb 2020 11:06:35 +0100 Subject: [PATCH 1/2] Fix android share plugin --- .../java/com/getcapacitor/plugin/Share.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java index d9c5d3753..a950079b0 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java @@ -27,13 +27,18 @@ public void share(PluginCall call) { return; } Intent intent = new Intent(Intent.ACTION_SEND); - // If they supplied both fields, concat em - if (text != null && url != null && url.startsWith("http")) { - text = text + " " + url; - intent.setTypeAndNormalize("text/plain"); + if (text != null) { + // If they supplied both fields, concat em + if (url != null && url.startsWith("http")) { + text = text + " " + url; + } intent.putExtra(Intent.EXTRA_TEXT, text); - } else if(url != null) { - if (url.startsWith("file:")) { + intent.setTypeAndNormalize("text/plain"); + } else if (url != null) { + if (url.startsWith("http")) { + intent.putExtra(Intent.EXTRA_TEXT, url); + intent.setTypeAndNormalize("text/plain"); + } else if (url.startsWith("file:")) { String type = getMimeType(url); intent.setType(type); Uri fileUrl = FileProvider.getUriForFile(getActivity(), getContext().getPackageName() + ".fileprovider", new File(Uri.parse(url).getPath())); From 608ef6c57ec3d4785a20c7b52ed387f16aa64fbd Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Wed, 12 Feb 2020 11:25:27 +0100 Subject: [PATCH 2/2] Add examples --- example/src/pages/share/share.html | 6 ++++++ example/src/pages/share/share.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/example/src/pages/share/share.html b/example/src/pages/share/share.html index 25e3bcf40..b5c0111e9 100644 --- a/example/src/pages/share/share.html +++ b/example/src/pages/share/share.html @@ -17,4 +17,10 @@ + + diff --git a/example/src/pages/share/share.ts b/example/src/pages/share/share.ts index 941f2391a..0c39aef5d 100644 --- a/example/src/pages/share/share.ts +++ b/example/src/pages/share/share.ts @@ -34,4 +34,18 @@ export class SharePage { console.log('Share return', shareRet); } + async showSharingTextOnly() { + let shareRet = await Share.share({ + text: 'Really awesome thing you need to see right meow', + }); + console.log('Share return', shareRet); + } + + async showSharingUrlOnly() { + let shareRet = await Share.share({ + url: 'http://ionicframework.com/', + }); + console.log('Share return', shareRet); + } + }