代码之家  ›  专栏  ›  技术社区  ›  Ashad

如何从链接共享图像,即不用下载图像,只需使用按钮共享即可

  •  2
  • Ashad  · 技术社区  · 6 年前

    我是android工作室的初学者,我认为这会很容易,但我也不明白

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

    任何帮助都将不胜感激。

    提前谢谢。

    2 回复  |  直到 6 年前
        1
  •  3
  •   ashad    6 年前

    首先您需要在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
  •  1
  •   Erselan Khan    6 年前

    实际上链接也是一个文本,所以你可以这样分享它:

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