Search code examples
androidandroid-contentprovider

How to open this contentURI?


I made an image viewer that (supposedly) opens attachments from email clients, that already opens correctly PNG files. In particular, I use K9, that sends an ACTION_VIEW intent with (basically) this code:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityIfAvailable(getContext(), intent);

When I click the attachment, my image viewer reports the following contentURI URL:

content://com.fsck.k9.tempfileprovider/temp/00ac996dc9f9539488ba4a6a349a8bf567267f5d?mime_type=image%2Fpng

I cannot find the /temp folder, so I guess I'm doing something wrong, and/or I don't know how to handle "providers"? How do I open this URI?


Solution

  • How do I open this URI?

    The same way you open any Uri with a content or file scheme:

    • Call getContentResolver() on a Context to get a ContentResolver
    • Call openInputStream() on the ContentResolver to get an InputStream on the content identified by the Uri