Getting path from Uri from Google Photos app

前端 未结 2 987
不知归路
不知归路 2021-01-12 16:49

I have an app which allows to select photos with an external app. Then I take the path of the photo from the uri and use it for internal actions.

When user selects a

2条回答
  •  生来不讨喜
    2021-01-12 17:07

    When user selects a photo with Google Photo, if the picture is locally stored then the next code works perfectly.

    Not necessarily. There is no requirement for that Uri to respond with a _data column to a query(). There is no requirement for the value it returns to be useful to you (e.g., a file on internal storage or removable storage that you cannot access).

    If you need the photo loaded into an ImageView, pass the Uri to an image-loading library, such as Picasso.

    If you need the bytes of the photo, use openInputStream() with ContentResolver to get an InputStream on the content identified by the Uri. Please open and read from the InputStream on a background thread.

提交回复
热议问题