简体   繁体   English

自定义内容提供程序和权限拒绝例外

[英]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. 在应用程序A中,我有一个数据库,可以从应用程序B中进行访问。我创建了自己的ContentProvider,以使应用程序B可以将数据写入应用程序A。但是,当我安装应用程序B然后安装应用程序A时,我得到了此异常-java.lang.SecurityException:权限拒绝:打开提供程序。 But when i am installing app A, and then B - everything is okay and apps can communicate via provider. 但是,当我安装应用程序A,然后安装B时-一切正常,应用程序可以通过提供程序进行通信。 And I am wondering is this a normal Android behavior or something gonna wrong? 我想知道这是正常的Android行为还是会出问题? 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 这是我的应用程序B清单的一部分

<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. 您应该首先安装App A(提供内容提供者和权限的应用程序),然后安装App B(访问内容提供者的应用程序)。

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. 缺点是两个应用程序都必须使用相同的签名证书才能运行,否则Android不允许您安装两个应用程序。

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? 请参阅此处的答案安装应用程序的顺序正在改变行为?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 权限拒绝:打开提供程序android.support.v4.content.FileProvider - Permission Denial: opening provider android.support.v4.content.FileProvider 安全异常:权限被拒绝 - Security Exception: Permission Denial 日历提供程序:Android 8上的权限拒绝 - Calendar Provider: Permission Denial on Android 8 java.lang.SecurityException:权限拒绝:实现内容提供者时打开提供者 - java.lang.SecurityException: Permission Denial: opening provider when implement content provider Android 10 - 文件提供程序 - 权限拒绝:读取 android.support.v4.content.FileProvider uri - Android 10 - file provider - permission denial: reading android.support.v4.content.FileProvider uri 权限拒绝:开放提供者Adobe Reader - Permission Denial: opening provider Adobe Reader 无法使用文件提供程序 java.lang.SecurityException 共享图像:权限被拒绝:读取 androidx.core.content.FileProvider uri - Unable to share Image using FIle Provider java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri 权限拒绝:打开未从 UID 1000 导出的提供程序 - Permission Denial: opening provider that is not exported from UID 1000 应用随机崩溃,显示权限被拒绝 - App crashes randomly ,show's permission denial exception 如何通过Admob安全例外阻止adob中的广告客户:权限拒绝 - How to block an advertiser in admob because of Admob Security Exception : Permission Denial
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM