Reputation: 421
I tried searching stackoverflow.com and tried every answer but none of them work.
I have a content provider and it was working when the user of the content provider is in the same application. However, I have Permission Denial error when accessing from another application.
LogCat
Caused by: java.lang.SecurityException: Permission Denial: opening provider com.abc.contentprovidersbooks.BooksProvider from ProcessRecord{4174b338 18673:com.abc.contentprovidersuserbooks/u0a10112} (pid=18673, uid=10112) requires com.abc.contentprovidersbooks.READ_DATABASE or com.abc.contentprovidersbooks.WRITE_DATABASE
Content Provider AndroidManifest:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.contentprovidersbooks"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.abc.contentprovidersbooks.ContentProvidersBook"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="BooksProvider"
android:authorities="com.abc.contentprovidersbooks.Books"
android:readPermission="com.abc.contentprovidersbooks.READ_DATABASE"
android:writePermission="com.abc.contentprovidersbooks.WRITE_DATABASE"
android:exported="true">
</provider>
</application>
Content Provider User application AndroidManifest:-
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tshouse.contentprovidersuserbooks"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="com.tshouse.contentprovidersbooks.READ_DATABASE"/>
<uses-permission android:name="com.tshouse.contentprovidersbooks.WRITE_DATABASE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:readPermission="com.tshouse.contentprovidersbooks.READ_DATABASE"
android:writePermission="com.tshouse.contentprovidersbooks.WRITE_DATABASE"
>
<activity
android:name="com.tshouse.contentprovidersbooks.ContentProvidersUserBooks"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Please advise how to declare the permission.
Thanks
Upvotes: 0
Views: 2659
Reputation: 1006819
If I had to guess, you installed the consumer app before the provider app, which will not work as you have it written.
If you put the <permission>
elements in both apps, then the install order will not matter.
Also, you cannot put android:readPermission
and android:writePermission
on <application>
, as you have in your consumer manifest. Simply delete those.
Upvotes: 2