android读取email数据库的权限问题

在自己的应用中使用email的uri来查询数据,结果提示需要ACCESS_PROVIDER的权限(<uses-permission android:name="com.android.email.permission.ACCESS_PROVIDER" />),添加后运行依然提示此错误:
代码如下:
Cursor cur = mContext.getContentResolver().query(
Uri.parse("content://com.android.email.provider/message"),null,null,null,null);

导致错误的原因如下:
因为Android本身自带的email应用的保护级别很高,是android:protectionLevel="signatureOrSystem",根据SDK的文档来讲signatureOrSystem这种权限的应用第三方的应用是无法单独访问的,此种权限保护级别需要system本身镜像应用或者是同system镜像具有相同的签名应用才可以访问,因此一般的第三方应用即使添加了permission也还是会报错的。


解决方法:(生成system.img)
1 将自己的应用方到android源代码的packages/apps/目录下,添加Android.mk文件
2 在应用程序的AndroidManifest.xml中的manifest节点中加入

android:sharedUserId="android.uid.system"这个属性。
3 修改Android.mk文件,加入LOCAL_CERTIFICATE := platform这一行
4 使用mm命令来编译,生成的apk就有同system一样的权限了。
5 在android根目录下用make snod重新生成system.img
6 启动emulator运行下应用看看是否好了。

网上还有另外一种方法,就是用signapk的方式。

permission可分四个等级

android:protectionLevel="normal"
android:protectionLevel="dangerous"
android:protectionLevel="signature"
android:protectionLevel="signatureOrSystem"

normal
The default value. A lower-risk permission that gives requesting applications access to isolated application-level features, with minimal risk to other applications, the system, or the user. The system automatically grants this type of permission to a requesting application at installation, without asking for the user's explicit approval (though the user always has the option to review these permissions before installing).

dangerous
A higher-risk permission that would give a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system may not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding, or some other approach may be taken to avoid the user automatically allowing the use of such facilities.

signature
A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.

signatureOrSystem
A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificates as those in the system image. Please avoid using this option, as the "signature" protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The "signatureOrSystem" permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值