sharing image with whatsapp in android

android, image, share, whatsapp

Solution

You have several problems.

First, `file:///assets/` is not a valid `Uri` on any version of Android. Your own application can refer to its own assets via `file:///android_asset/`.

Second, only you can access your own assets via `file:///android_asset/` -- you cannot pass such a `Uri` to third-party apps. Either copy the file from assets into internal storage and use `FileProvider`, or you can try my `StreamProvider` and try to share the data straight out of `assets/`.

Third, there is no guarantee that `com.whatsapp` exists on the device, or that `com.whatsapp` will support `ACTION_SEND` of `file:///` `Uri` values with a MIME type of `image/*`, and so you may crash with an `ActivityNotFoundException`.

Fourth, the user might want to share this image via some other means than WhatsApp. Please allow the user to share where the user wants, by removing the `setPackage()` call from your `Intent`.

Problem

I have image in assets folder and need to share it with whatsapp application I tried this code , it keeps give me sharing failed try again ! what's wrong ?! ``` Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.setPackage("com.whatsapp"); // share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("file:///assets/epic/adv.png"))); share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///assets/epic/adv.png")); this.startActivity(Intent.createChooser(share, "share_via")); ```

Original source

Related problems