Steve Warner Steve Warner - 23 days ago 7
Android Question

Uri permission is not granted to a path of provider

I have a provider in my app

<provider android:authorities="com.myapp.android.provider" android:exported="false" android:name="com.myapp.android.provider.FileSystemProvider">
<grant-uri-permission android:pathPrefix="/"/>
</provider>


And when I call the following intent:

Intent intent = new Intent();
intent.setClassName(getPackageName(), "com.myapp.android.CameraActivity");
intent.setData(Uri.parse("content://com.myapp.android.provider/"));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);


I get exception


Caused by: java.lang.SecurityException: Permission Denial: starting
Intent { dat=content://com.myapp.android.provider/ flg=0xc3
cmp=com......../com......... (has extras) } from
ProcessRecord{44955bc0 9477:com...../u0a260} (pid=9477,
uid=10260) not exported from uid 10261


What I do wrong? I tried to specify full path to a file or different directory, but it never worked.

Answer Source
intent.setClassName(getPackageName(), "com.myapp.android.CameraActivity");

Most likely, this is not the actual line of code that is in your app; your real code is specifying some other app. Regardless, this component is not exported, and therefore you cannot access it from your app.