Skip to content

Commit

Permalink
Merge pull request OpenFlutter#55 from Nag112/master
Browse files Browse the repository at this point in the history
Fixed share failed, please try again later issue
  • Loading branch information
lizhuoyuan authored Sep 13, 2021
2 parents eee0a2b + fc7c793 commit b6d0f65
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,22 @@ public void onError(FacebookException error) {
private void shareWhatsApp(String imagePath, String msg, Result result, boolean shareToWhatsAppBiz) {
try {
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("*/*");

whatsappIntent.setPackage(shareToWhatsAppBiz ? "com.whatsapp.w4b" : "com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, msg);
// if the url is the not empty then get url of the file and share
if (!TextUtils.isEmpty(imagePath)) {
whatsappIntent.setType("*/*");
System.out.print(imagePath+"url is not empty");
File file = new File(imagePath);
Uri fileUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file);
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
whatsappIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
else {
whatsappIntent.setType("text/plain");
}
activity.startActivity(whatsappIntent);
result.success("success");
} catch (Exception var9) {
Expand Down

0 comments on commit b6d0f65

Please sign in to comment.