【问题标题】:How to share image from link ,i.e, without downloading the image just share using a button如何从链接共享图像,即不下载图像只需使用按钮共享
【发布时间】:2018-09-01 15:32:21
【问题描述】:

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

如何从链接分享图片,即不下载图片,只需在社交媒体上分享,比如什么应用程序。我可以下载图片,然后分享然后删除,但我不想这样做。我正在使用 glide 库在图像视图中加载图像,然后当用户单击一个按钮时,它只会共享它在图像视图中显示的图像以及我拥有的链接,然后返回到应用程序。

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

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

  • 如果您想知道分享后删除的信息,请通知我

标签: android android-intent android-glide android-sharing


【解决方案1】:

首先您需要在 glide 中加载图像(当您使用 glide 时)然后您可以将其共享到任何地方,但图像将被保存到存储中

从 glide 加载图像的代码(图像正在保存到存储中,您可以稍后将其删除)

       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);
                        }
});

如果您愿意,可以通过添加更多代码从存储中删除该图像

【讨论】:

    【解决方案2】:

    其实link也是一个文本,所以你可以这样分享:

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, yourUrlOfImage);
    sendIntent.setType("text/plain");
    startActivity(sendIntent);
    

    【讨论】:

      猜你喜欢
      • 2020-07-21
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多