Unable to send images to other apps, tried hike, Messenger and Whatsapp
<p>I am trying to share images from my app to other app (Hike, Facebook, Messenger etc) but every time I am getting different error. Gone through almost every Q&amp;A but problem not solved yet.</p>

<p><strong>This is my code</strong>:</p>

<pre><code>                       filepath = Environment.getExternalStorageDirectory();
                       cacheDir = new File(filepath.getAbsolutePath()
                       + "/LikeIT/");
                       cacheDir.mkdirs();
                       Intent intent = new Intent();
                       intent.setType("image/jpeg");
                       intent.setAction(Intent.ACTION_SEND);

                       intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(cacheDir
                                       .getAbsolutePath())));
                       intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

                       activity.startActivity(intent);
</code></pre>

<p><strong>I have changed the below line many times, but didn't get the solution:</strong></p>

<pre><code>    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(cacheDir
                                       .getAbsolutePath())));       
</code></pre>

<p><strong>I have changed this with</strong>:</p>

<pre><code>  1.  intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(str1));
  2.  intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(file1);
</code></pre>

<p>but didn't get as needed. And also when i am sending image to Whatsapp it is not showing image, and after sending it is showing.</p>

<p><a href="https://i.stack.imgur.com/B6NTu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6NTu.png" alt="enter image description here"></a></p>