-1

I have a gridview, clicking any image in the gridview expands it to a bigger image view, in this image view i can swipe left and right to change my images, i have added a method that would let me share the image to other apps like facebook watsapp etc. But the method seems to be not quite right, i cant figure out my mistake. It opens the popup window showing options to share the image but when i choose any option to send the image it says, Couldn't Load The Image.

Have a look at my code:

else {



                    if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {

                            URL url2 = new URL((thumb[j]));
                            Bitmap bimage = BitmapFactory.decodeStream(url2
                                    .openConnection().getInputStream());
                            shareImage();

                            Toast.makeText(getApplicationContext(),
                                    "Saving to Favorites", Toast.LENGTH_LONG)
                                    .show();



                        }

                    }

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }

    }



    private void shareImage() {
        Intent share = new Intent(Intent.ACTION_SEND);

        // If you want to share a png image only, you can do:
        // setType("image/png"); OR for jpeg: setType("image/jpeg");
        share.setType("image/*");

        // Make sure you put example png image named myImage.png in your
        // directory
        String bimage = Environment.getExternalStorageDirectory()
                + thumb[j];

        File imageFileToShare = new File(bimage);

        Uri uri = Uri.fromFile(imageFileToShare);
        share.putExtra(Intent.EXTRA_STREAM, uri);

        startActivity(Intent.createChooser(share, "Share Image!"));
    }
}

Whereas thumb is the array having all the resource ids of the image, "j" is the int who's value initiated to 0.

Using the gesture to initiate the code.

I am ready to share my full code for greater understanding.

Any help would highly be appreciated.

  • Are you sure you are getting something in bimage. – Pavya May 02 '15 at 11:18
  • @user3676184 i didnt get your question much, but yes, swiping left and right changes the images in my image view and thats working fine, now just need to share any image from the image view. – Milly Corsh May 02 '15 at 11:22
  • http://stackoverflow.com/questions/7661875/how-to-use-share-image-using-sharing-intent-to-share-images-in-android check this link – Pavya May 02 '15 at 11:27
  • @user3676184 How should this be modified for my case? Uri screenshotUri = Uri.parse("android.resource://com.android.test/*"); – Milly Corsh May 02 '15 at 11:32
  • make sure your path is correct. – Pavya May 02 '15 at 11:42
  • @user3676184 Again the exact same error, what am i doing wrong, i declared Uri screenshotUri = Uri.parse((thumb[j])); – Milly Corsh May 02 '15 at 11:56
  • @user3676184 given every detail of my problem, The popup window appears but when i share the image it says image load fail – Milly Corsh May 02 '15 at 13:08
  • possible duplicate of [Trying to share the image](http://stackoverflow.com/questions/30003555/trying-to-share-the-image) – Mattia Maestrini May 04 '15 at 05:43

1 Answers1

0
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);

    sharingIntent.setType("image/jpeg");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    startActivity(Intent.createChooser(sharingIntent, "Share image using")); 
Hardik Parmar
  • 712
  • 2
  • 13
  • 28