How to share image from link ,i.e, without downloading the image just share using a button
How to share image from link ,i.e, without downloading the image just share using a button
I am beginner in android studio and i think it will be easy but also I am not getting that
How to share image from link ,i.e, without downloading the image just share on social media like whats app .I can download the image and then share and then delete that but I do not want to do that. I am using glide library to load the image in Image view and then when a user click on a button it will just share its image which is showing in image view and whose link i have and then come back to the app.
I am using Glide library for loading image.
Any help will be grateful.
Thanks in advance.
2 Answers
2
first you need to load image in glide(as you are using glide ) then you can share it to anywhere but image will be saved to storage
code to load image from glide (image is being saved to storage, you can delete it later)
Glide.with(getApplicationContext())
.load(imagelink) \link of your image file (url)
.asBitmap().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
.into(new SimpleTarget<Bitmap>(250, 250)
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = MediaStore.Images.Media.insertImage(getContentResolver(), resource, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable)
Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
super.onLoadFailed(e, errorDrawable);
@Override
public void onLoadStarted(Drawable placeholder)
Toast.makeText(getApplicationContext(), "Starting", Toast.LENGTH_SHORT).show();
super.onLoadStarted(placeholder);
);
If you want then delete that image from storage by adding some more code
Actually link is also a text, so you can share it like this:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, yourUrlOfImage);
sendIntent.setType("text/plain");
startActivity(sendIntent);
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
if you want the know about deleting after sharing then do notify me
– ashad
Oct 23 at 13:47