Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 209
Ashad Nasim Avatar asked Sep 01 '18 15:09

Ashad Nasim


1 Answers

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

like image 87
ashad Avatar answered Oct 16 '22 17:10

ashad