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.