我有一个带ContentProvider
的应用:
<provider android:name="ExampleProvider"
android:readPermission="example.contentprovider.READ"
android:label="Example Content Provider"
android:authorities="example.contentprovider.provider"
/>
,另一个应用程序请求访问提供程序的权限:
<uses-permission android:name="example.contentprovider.READ" />
但是当我运行第二个应用程序时,我得到了
E/AndroidRuntime( 818): java.lang.RuntimeException: Unable to start activity
ComponentInfo{example.contentresolver/example.contentresolver.ContentResolverActivity}:
java.lang.SecurityException: Permission Denial: reading example.contentprovider.ExampleProvider
uri content://example.contentprovider.provider/words from pid=818, uid=10045
requires example.contentprovider.READ, or grantUriPermission()
为什么我收到此错误?
答案 0 :(得分:2)
您应首先在创建ContentProvider的应用中定义权限,然后使用它。
<permission android:name="example.contentprovider.READ"
android:permissionGroup="..."
android:label="@string/perm_read"
android:description="@string/perm_read_summary"
android:protectionLevel="dangerous" />
答案 1 :(得分:1)
确保android:exported = true;