简体   繁体   中英

Custom content provider and Permission Denial exception

) I have two apps. In the app A i have a database, which can be accessed from app B. I created my own ContentProvider to give app B an access to write data to app A. But when i am installing an app B and then app A - i get this exception - java.lang.SecurityException: Permission Denial: opening provider. But when i am installing app A, and then B - everything is okay and apps can communicate via provider. And I am wondering is this a normal Android behavior or something gonna wrong? Thanks

Edit

This is my a piece from my app A manifest

<permission android:name="com.myapp.READ_DATABASE" android:protectionLevel="normal" />
<permission android:name="com.myapp.WRITE_DATABASE" android:protectionLevel="normal" />

<provider android:authorities="....."
            android:name="......"
            android:exported="true"
            android:readPermission="com.myapp.READ_DATABASE"
            android:writePermission="com.myapp.WRITE_DATABASE">
        </provider>

And this is a part from my app B manifest

<uses-permission android:name="com.myapp.READ_DATABASE"/>
<uses-permission android:name="com.myapp.WRITE_DATABASE"/>

Your problem is the order of app installation. You should first install App A, the one providing the content provider and the permission, and then install App B, the one accessing the content provider.

Ok, I have found an answer, but it has its drawbacks. You need to add the permission attribute to BOTH apps in the manifest.

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

The drawback is that both apps need to be using the same signing certificate for this to work, otherwise Android will not let you install both apps.

Also note that the consuming app should use a protection level of signature

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

See answer here Order of installing the application is changing the behaviour?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM