android share image from url

前端 未结 10 1860
攒了一身酷
攒了一身酷 2020-12-01 07:50

I want to share an image using the code:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri imageUri = Uri.parse(\"http://stacktoheap.com/images/stac         


        
10条回答
  •  独厮守ぢ
    2020-12-01 08:52

    First you need to load image in the glide. Then you can share it to anywhere. 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);
       Log.i("quoteswahttodo", "is onresoursereddy" + path);
    
       Uri screenshotUri = Uri.parse(path);
    
       Log.i("quoteswahttodo", "is onresoursereddy" + screenshotUri);
    
       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);
      }
     });
    

提交回复
热议问题