How to share image from link ,i.e, without downloading the image just share using a button

荒凉一梦 提交于 2019-12-06 15:42:36

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!