user3328051
user3328051

Reputation: 57

Custom content provider access from another app

I have two apps. one of the two has a custom content provider which works like a charm.

APP A -> The one with the provider

APP B -> The one that needs the data from the provider

Everything works fine in this scenario:

1st : Install app A

2nd: Install app B

However when I do it like this:

1st: Install app B

2nd: Install app A

I get the error :

09-19 13:07:22.576: E/AndroidRuntime(14621): Caused by: java.lang.SecurityException: Permission Denial: opening provider 
uk.co.ringsizer.ui.BirthProvider from ProcessRecord{450c14c8 14621:uk.co.gemtv/u0a360} 
(pid=14621, uid=10360) requires com.eir.provider.Size.READ_DATABASE 
or com.eir.provider.Size.WRITE_DATABASE

My permissions are clearly stated in the manifest file and they are correct since it works if I install the apps in a different order.

It's the first time I'm using Content provider and I am relatively new to Android so the problem might be obvious to more experienced developers.

Any ideas? Has anybody else experienced the same issue before?

Thanks in advance.

Upvotes: 1

Views: 1667

Answers (2)

Nick Wright
Nick Wright

Reputation: 1413

Make sure that BOTH apps have the permission attribute in the manifest.

<permission android:name="com.example.permission.READ" />

I had only the use-permission attribute in the consuming app, and had exactly this problem. It'll work if the content provider app is installed first, but will fail if the content provider app is installed second.

When the consuming client app has the permission attribute as well, it will work regardless of app install order.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006819

The app that defines the custom <permission> must be installed before the app that requests it via <uses-permission>. If they are installed in the wrong order, the <uses-permission> app does not get the permission and must be uninstalled and reinstalled.

Custom permissions in general are risky for SDK apps.

Upvotes: 3

Related Questions