Getting the Absolute File Path from Content URI for searched images

后端 未结 2 695
再見小時候
再見小時候 2020-11-21 22:53

I am trying to share images from other applications to my application using implicit intent ACTION_SEND.

While sharing search images from chrome browser, app receiv

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 23:50

    If you absolutely need a local copy of the file, you are going to need to open the InputStream copy the contents to a local file that you know the path to and then go from there. Sidenote: Guava's ByteStreams#copy is an easy way to accomplish this.

    Of course this file is no longer backed by the original Uri source, so I don't think this is what you want. Instead, you should work with the Uri's intended API. Take a look at the Storage Access Framework

    Edit

    Here is how you can get an InputStream from your Uri

    InputStream inputStream = getContentResolver().openInputStream(uri);
    

提交回复
热议问题