在另一个应用程序中访问内容提供者的安全异常
Security Exception accessing Content Provider in another application
我正在尝试创建一个仅供由同一证书签名的应用程序使用的内容提供程序。
我已经这样声明了内容提供者
<provider
android:name=".MyProvider"
android:authorities="com.example.provider"
android:permission="com.example.permissions.USER_PERMISSION"
android:readPermission="com.example.permissions.USER_PERMISSION_READ"
android:writePermission="com.example.permissions.USER_PERMISSION_WRITE"
android:exported="true">
</provider>
我已经声明了签名保护级别的权限
很好,但是当我尝试从其他应用程序访问提供程序时,如下所示:
//Create an URI that will be used to check the status of the content provider
Uri myURI = Uri.parse("content://com.example.provider");
ContentResolver contentResolver = getContentResolver();
try {
contentResolver.insert(prototypeURI,null);
} catch (Exception e) {
e.printStackTrace();
}
我得到一个SecurityException: Permission Denial: opening provide ... requires com.example.permissions.USER_PERMISSION_READ
。
有什么想法吗?
首先,使用 android:permission
或 android:readPermission
和 android:writePermission
的组合。
其次,需要先安装具有定义这些权限的 <permission>
元素的应用程序。
第三,其他应用需要相应的<uses-permission>
元素以获得必要的权限。
我发现了问题。
其中一个应用程序通过 gradle.build 签名配置使用了不同的调试密钥集。
我正在尝试创建一个仅供由同一证书签名的应用程序使用的内容提供程序。 我已经这样声明了内容提供者
<provider
android:name=".MyProvider"
android:authorities="com.example.provider"
android:permission="com.example.permissions.USER_PERMISSION"
android:readPermission="com.example.permissions.USER_PERMISSION_READ"
android:writePermission="com.example.permissions.USER_PERMISSION_WRITE"
android:exported="true">
</provider>
我已经声明了签名保护级别的权限
很好,但是当我尝试从其他应用程序访问提供程序时,如下所示:
//Create an URI that will be used to check the status of the content provider
Uri myURI = Uri.parse("content://com.example.provider");
ContentResolver contentResolver = getContentResolver();
try {
contentResolver.insert(prototypeURI,null);
} catch (Exception e) {
e.printStackTrace();
}
我得到一个SecurityException: Permission Denial: opening provide ... requires com.example.permissions.USER_PERMISSION_READ
。
有什么想法吗?
首先,使用 android:permission
或 android:readPermission
和 android:writePermission
的组合。
其次,需要先安装具有定义这些权限的 <permission>
元素的应用程序。
第三,其他应用需要相应的<uses-permission>
元素以获得必要的权限。
我发现了问题。 其中一个应用程序通过 gradle.build 签名配置使用了不同的调试密钥集。