Getting the Absolute File Path from Content URI for searched images

后端 未结 2 703
再見小時候
再見小時候 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:35

    How can I fetch file path from this type of Content URI?

    You don't, as there does not have to be a file at all behind the Uri, let alone one that you can access. That Uri might point to:

    • A local file on external storage
    • A local file on internal storage for the other app
    • A local file on removable storage
    • A local file that is encrypted and needs to be decrypted on the fly
    • A stream of bytes held in a BLOB column in a database
    • A piece of content that needs to be downloaded by the other app first
    • ...and so on

    All other apps like Facebook, Google+ are doing it

    No, they are not. They are using ContentResolver and:

    • openInputStream() to read in the bytes associated with the content
    • getType() to get the MIME type associated with the content
    • query() and the OpenableColumns to get the size and display name associated with the content

提交回复
热议问题