1

I'm trying to share an image with an intent to social media. It's asking for the path to the image, and I've retrieved the image URL from my object, in the form of files.parsetfss.com/77c6003f-0d1b-4b55-b09c-16337b3a2eb8/tfss-7267d2df-9807-4dc0-ad6f-0fd47d83d20f-3eb7b9e4-d770-420c-a0a0-9ca4fc4a6a0a_1.png, for example. The share intent displays but when I open any other app to share, I get a crash with no logcat error. What could be going wrong?

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, marketFeedItem.getDesign().getImage());
startActivity(Intent.createChooser(share, "Share your design!"));

Updated Answer. This is what I did to get it to work:

  ImageView imageView = (ImageView) feedItemView.findViewById(R.id.image);
                Drawable mDrawable = imageView.getDrawable();
                Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();

                String path = MediaStore.Images.Media.insertImage(getContentResolver(),
                        mBitmap, "Design", null);

                Uri uri = Uri.parse(path);

                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("image/*");
                share.putExtra(Intent.EXTRA_STREAM, uri);
                share.putExtra(Intent.EXTRA_TEXT, "I found something cool!");
                startActivity(Intent.createChooser(share, "Share Your Design!"));
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153

3 Answers3

2

If getImage() is returning the long string that you have in your question, that is not a valid URL, as it lacks a scheme.

According to the docs, you need to pass a content: Uri in the EXTRA_STREAM extra. In practice, a file: Uri frequently also works. I would expect you to run into problems with other schemes, like https: or http:.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

maybe this helps share image with URL android share intent

Community
  • 1
  • 1
yital9
  • 6,544
  • 15
  • 41
  • 54
  • Kind of! I tried that method and it was giving me ``FileNotFoundException`` with ``open failed: ENOENT (No such file or directory)``. – Martin Erlic Mar 06 '16 at 17:41
  • generally you have to save the image from url to your local storage and share this local bitmap – yital9 Mar 06 '16 at 17:45
1

URL of your parse server for the image file is not a valid for share intent, so save loaded bitmap temporary in your device then share image using that saved bitmap URL. After image shared you can delete saved image from your device

Android Leo
  • 666
  • 1
  • 8
  • 24
  • Like this? ``URL url = new URL(marketFeedItem.getDesign().getImage()); Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());`` then use image in the share extra? – Martin Erlic Mar 06 '16 at 23:48
  • Use Universal Image Loader = >https://github.com/nostra13/Android-Universal-Image-Loader, it is the great library to manage image loading process from the server. It will provide ImageLoadingListener which return image url with loaded bitmap – Android Leo Mar 07 '16 at 06:59