title: How to share image URL to WhatsApp in Android?
body: <p>I need to share an image to WhatsApp in my app. I have the image URL. For sharing to WhatsApp, I am using the following code.</p>
  
  <pre><code>String image_url = "http://images.cartradeexchange.com//img//800//vehicle//Honda_Brio_562672_5995_6_1438153637072.jpg";
  
  URI uri = null;
  try {
      uri = new URI(image_url.toString());
  } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  Log.e("uri=", "" + uri);
  Intent shareIntent = new Intent();
  shareIntent.setAction(Intent.ACTION_SEND);
  shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
  shareIntent.setType("image/jpg");
  
  // Target whatsapp:
  shareIntent.setPackage("com.whatsapp");
  shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  
  try {
      startActivity(shareIntent);
  } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(InventoryManageOnlineActivity.this,
              "Whatsapp have not been installed.",
              Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  
  <p>But it didn't work. I am getting the following error.</p>
  
  <pre><code>08-26 11:57:34.674: W/Bundle(19447): Key android.intent.extra.STREAM expected Parcelable but value was a java.net.URI.  The default value &lt;null&gt; was returned.
  08-26 11:57:34.738: W/Bundle(19447): Attempt to cast generated internal exception:
  08-26 11:57:34.738: W/Bundle(19447): java.lang.ClassCastException: java.net.URI cannot be cast to android.os.Parcelable
  08-26 11:57:34.738: W/Bundle(19447):    at android.os.Bundle.getParcelable(Bundle.java:810)
  08-26 11:57:34.738: W/Bundle(19447):    at android.content.Intent.getParcelableExtra(Intent.java:4850)
  08-26 11:57:34.738: W/Bundle(19447):    at android.content.Intent.migrateExtraStreamToClipData(Intent.java:7548)
  08-26 11:57:34.738: W/Bundle(19447):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545)
  08-26 11:57:34.738: W/Bundle(19447):    at android.app.Activity.startActivityForResult(Activity.java:3746)
  08-26 11:57:34.738: W/Bundle(19447):    at android.app.Activity.startActivityForResult(Activity.java:3707)
  08-26 11:57:34.738: W/Bundle(19447):    at android.app.Activity.startActivity(Activity.java:4027)
  08-26 11:57:34.738: W/Bundle(19447):    at android.app.Activity.startActivity(Activity.java:3989)
  08-26 11:57:34.738: W/Bundle(19447):    at com.cartradrexchange.inventory.InventoryManageOnlineActivity$ManageOnlineAdapter.onClick(InventoryManageOnlineActivity.java:441)
  08-26 11:57:34.738: W/Bundle(19447):    at android.view.View.performClick(View.java:4761)
  08-26 11:57:34.738: W/Bundle(19447):    at android.view.View$PerformClick.run(View.java:19767)
  08-26 11:57:34.738: W/Bundle(19447):    at android.os.Handler.handleCallback(Handler.java:739)
  08-26 11:57:34.738: W/Bundle(19447):    at android.os.Handler.dispatchMessage(Handler.java:95)
  08-26 11:57:34.738: W/Bundle(19447):    at android.os.Looper.loop(Looper.java:135)
  08-26 11:57:34.738: W/Bundle(19447):    at android.app.ActivityThread.main(ActivityThread.java:5312)
  08-26 11:57:34.738: W/Bundle(19447):    at java.lang.reflect.Method.invoke(Native Method)
  08-26 11:57:34.738: W/Bundle(19447):    at java.lang.reflect.Method.invoke(Method.java:372)
  08-26 11:57:34.738: W/Bundle(19447):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
  08-26 11:57:34.738: W/Bundle(19447):    at com.android.internal.os.ZygoteInit.main(Zygote
  </code></pre>
  
  <p>For that, I searched a lot in Google, and I followed the below URL </p>
  
  <p><a href="https://stackoverflow.com/questions/19306417/android-sharing-image-doesnt-work">Android sharing image doesn&#39;t work</a>.</p>
  
  <p>But it is not useful for me. Please show me how to share image URLs.</p>