问题
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.
回答1:
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
回答2:
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);
来源:https://stackoverflow.com/questions/52129608/how-to-share-image-from-link-i-e-without-downloading-the-image-just-share-usin