-1

I'm trying to share GIF file. I want to share it via any social networking apps, I have a problem with file name. I don't how to get name file. This is my code:

llsetwallpapers.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // set as wallpapers
            lt.setText("Please Wait ...");
            lt.setTranslationY(100);
            lt.show();
            Glide.with(getApplicationContext())
                    .load(url)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new SimpleTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(Bitmap resource, GlideAnimation<?super Bitmap> glideAnimation) {
                            File file = new File file = new File(getApplicationContext().getExternalCacheDir() , namefile)
                            file.setReadable(true);
                            Uri uri = Uri.fromFile(file);
                            Intent shareIntent = new Intent();
                            shareIntent.setAction(Intent.ACTION_SEND);
                            shareIntent.setType("image/gif");
                            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                            startActivity(Intent.createChooser(shareIntent, "Share with"));
                        }
                    });
        }
    });
Zoe
  • 27,060
  • 21
  • 118
  • 148
MrMR
  • 279
  • 6
  • 16

1 Answers1

1

The problem you are trying to solve is discussed at github issues, where RĂ³bert Papp has provided an example implementation for sharing a file downloaded by Glide.

The key part for you - is to get a reference to the File. That can be done with downloadOnly():


    File file = Glide
                    .with(context)
                    .load(url)
                    .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                    .get()

Having a File, you can use FileProvider API in order to share the file.

azizbekian
  • 60,783
  • 13
  • 169
  • 249