I have 2 apps - Demo and Pro. Demo has a content provider and when Pro is installed it needs to transfer all files from the demo provider.
Demo app (provider):
<provider
android:name="***.provider.InternalStorageProvider"
android:authorities="***.demo.storage.int.provider"
android:exported="false"
android:syncable="true"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/int_storage_paths" />
</provider>
Pro app (consumer):
Experiment 1:
ParcelFileDescriptor pfd = cr.openFileDescriptor(exposedFileUri, "r");
FileInputStream input = new FileInputStream(pfd.getFileDescriptor());
java.lang.SecurityException: Permission Denial: opening provider .provider.InternalStorageProvider from ProcessRecord{9c85875 10734:/u0a61} (pid=10734, uid=10061) that is not exported from uid 10062
Experiment 2:
Activity activity = getActivity(); activity.grantUriPermission(activity.getPackageName(), exposedFileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
ParcelFileDescriptor pfd = cr.openFileDescriptor(exposedFileUri, "r"); FileInputStream input = new FileInputStream(pfd.getFileDescriptor());
java.lang.SecurityException: Uid 10061 does not have permission to uri 0 @ content://***.demo.storage.int.provider/db/file1
InternalStorageProvider
is a copy of a normal FileProvider
. But it doesn't matter as the execution cannot even reach it. Exceptions are thrown before it is called.
Note that no chooser activities and intents are involved. The consumer tries to open the file from a known uri directly, without choosers. Most of the examples I've found are using Intent.FLAG_GRANT_READ_URI_PERMISSION
but I don't use an intent at all.
How I am supposed to grant uri permissions to the consumer correctly?
FLAG_GRANT_READ_URI_PERMISSION
to absolutely every other intent that was making use of the URI inside my app – Clifton