android share image in ImageView without saving in sd card

前端 未结 3 1201
一生所求
一生所求 2021-02-05 15:55

I want to Share the image in image view.but i don\'t want save to SDcard. But when i use Intent to share i used code

Intent share = new Intent(Intent.ACTION_         


        
3条回答
  •  青春惊慌失措
    2021-02-05 16:34

    I was able to do this:

    File file = new File( getCacheDir(), "screenshot.png");
    ...
    file.setReadable(true, false);
    Uri uri = Uri.fromFile(file);
    ...
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    

    This way I save the file in my own cache folder, so I'm not fooling with any public folders or depending on the sd card being present.

    Also, this way it gets deleted automatically if the user removes my app, but I also used startActivityForResult/onActivityResult to delete the file and set its folder back to private when the share is finished.

    (Personally I was hoping to find a way to share a bitstream and avoid the step of creating a file entirely, but I don't think that is possible.)

    [EDIT: I discovered this doesn't work on 2.3.6 where the file MUST be on file:///mnt/sdcard.]

提交回复
热议问题