如何从链接共享图像,即无需下载图像,只需使用按钮即可共享 [英] How to share image from link ,i.e, without downloading the image just share using a button

查看:104
本文介绍了如何从链接共享图像,即无需下载图像,只需使用按钮即可共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android studio的初学者,我认为这很容易,但我也没有得到

I am beginner in android studio and i think it will be easy but also I am not getting that

如何从链接共享图像,即不下载图像只是在社交媒体(如whats app)上共享。我可以下载图像,然后共享然后删除它,但我不想这样做。我正在使用glide库将图像加载到图像视图中,然后当用户单击一个按钮时,它将仅共享其图像,该图像显示在图像视图中并且具有我的链接,然后返回到应用程序。

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.

我正在使用Glide库加载图像。

I am using Glide library for loading image.

任何帮助将不胜感激。

谢谢。

推荐答案

首先,您需要在glide中加载图像(因为您正在使用glide)那么您可以将其共享到任何地方,但是图像将被保存到存储中

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

这篇关于如何从链接共享图像,即无需下载图像,只需使用按钮即可共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆