Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): allow Share plugin to provide text or url only #2436

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
6 changes: 6 additions & 0 deletions example/src/pages/share/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
<button (click)="showSharing()" ion-button>
Show Sharing
</button>
<button (click)="showSharingTextOnly()" ion-button>
Show Sharing (text only)
</button>
<button (click)="showSharingUrlOnly()" ion-button>
Show Sharing (url only)
</button>
</ion-content>
14 changes: 14 additions & 0 deletions example/src/pages/share/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}