Skip to content

Commit

Permalink
fix(android): allow Share plugin to provide text or url only (#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce authored Mar 17, 2020
1 parent 62b11fd commit b6328f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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 @@ -28,13 +28,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);
}

}

0 comments on commit b6328f0

Please sign in to comment.