androiduriandroid-fileprovider

How can I use file Uri from another app Intent in Android


In my APP I received the Uri of a pdf file from any other app that can share pdfs.

Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);

Anyway I cannot full-use this Uri, I image because of it is from a FileProvider external to my app. For example when I try to create a FileDescriptor:

ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(uri, "r");

I get this error:

W/System.err: java.lang.SecurityException: Permission Denial: opening provider androidx.core.content.FileProvider from ProcessRecord{...} (pid=23606, uid=10525) that is not exported from UID 10123

It is really necessary get the file path, copy the file, and get a new Uri? Or I can simply manage the original Uri in some way ?


Solution

  • As per my knowledge the best thing to do is to read/copy the data from content provider immediately and then use that data to do whatever you want. so don't waste your time trying to manage the original one. I hope its helpful to you