在自己的应用中使用email的uri来查询数据,结果提示需要ACCESS_PROVIDER的权限,添加后运行依然提示此错误,实在找不到原因了,访问通话记录与短信时添加完权限后都无此问题。
代码如下:
Cursor cur = mContext.getContentResolver().query(
Uri.parse("content://com.android.email.provider/message"),
null,
null,
null,
null);
报错没有的权限是<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);
报错没有的权限是<uses-permission android:name="com.android.email.permission.ACCESS_PROVIDER" />,但确实是添了的。
解决方案 »
- app展示数据需要校验处理吗?
- monkeyrunner安卓自动化中,为什么命令重启后不能拖拽屏幕, 请高手指教
- Android中如何固定媒体播放音量而不受音量键控制
- 关于 layout_weight 的问题
- 安卓手机系统怎么更新?
- 关于Listview菜鸟问题
- Android 百度地图自定义覆盖物
- 关于fragment操作报错Activity has been destroyed的问题?
- android开发入门学习大集合
- Android Studio 打包后APK与Debug运行情况不一致问题请教
- 关于最后的bitmap 无法保存绘制图的问题,求看看问题在哪
- android GridView (图片+文字)OnItemClickListener中怎样得到图片并显示在对话框中
2.x:content://com.android.contacts/data/emails
1.6:Contacts.ContactMethods.CONTENT_URI
但还有一个问题请问,若是按照此uri访问那么访问的数据库还是data/data/com.android.eamil/databases/EmailProvider.db吗,我要再继续访问里面的表message或account数据那么此uri后面还需要添/message与/account吗?若不是此数据库文件那么又是哪个呢?
还是要谢谢您的帮助!
看看sdk中的
ContactsContract.CommonDataKinds.Email
Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
Cursor c = getContentResolver().query(uri,
new String[]{Email.DISPLAY_NAME, Email.DATA},
null, null, null); Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
Cursor c = getContentResolver().query(uri,
new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
null, null, null); 试试SDK的方法吧
而且还有个问题,这里搜索的email信息有可能只是gmail的信息,但是不一定是其他email邮箱的信息。
因为Android本身自带的email应用的保护级别很高,是android:protectionLevel="signatureOrSystem",从android sdk自带文档了解到此种权限保护级别需要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运行下应用看看是否好了。
由于我这里的email数据库没有任何信息,我只好打出来columns来看,和我期望读取的一样。网上还有另外一种方法,但我用signapk报错了所以也就不介绍了,等解决好了再继续介绍。
困扰了好久的问题终于解决了希望能对大家都有帮助。
因为Android本身自带的email应用的保护级别很高,是android:protectionLevel="signatureOrSystem",从android sdk自带文档了解到此种权限保护级别需要system本身镜像应用或者是同system镜像具有相同的签名应用才可以访问,因此一般的第三方应用即使添加了permission也还是会报错的。
这个permission我学习过,有四种格式似乎!
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.
根据SDK的文档和查的资料来讲signatureOrSystem这种权限的应用第三方的应用时无法单独访问的,要么把自己的应用一同生成system.img,要么就得和system.img具有一样的签名。像我这个若单独做个应用的话那么肯定是实现不了的,因为每款机器签名肯定都不一样,解决的办法就是把软件集成到手机厂商的img里面。因此你说的放到真机里面肯定不行的,它不能作为一款第三方软件发布,若将已经集成的img文件重新烧一下手机的话我想应该是可以的了。
[email protected]
我用的是SDK2.3,也查了就没有你这个provider,Email.CONTENT_LOOKUP_URI就更加没有了,直接报错!
data_version
phonetic_name
phonetic_name_style
contact_id
lookup
data12
data11
data10
mimetype
data15
data14
data13
display_name_source
data_sync1
data_sync3
data_sync2
contact_chat_capability
data_sync4
account_type
custom_ringtone
status
data1
data4
data5
data2
data3
data8
data9
group_sourceid
data6
account_name
data7
display_name
in_visible_group
display_name_alt
contact_status_res_package
is_primary
contact_status_ts
raw_contact_id
times_contacted
contact_status
status_res_package
status_icon
contact_status_icon
mode
version
last_time_contacted
res_package
_id
name_verified
status_ts
dirty
is_super_primary
photo_id
send_to_voicemail
name_raw_contact_id
contact_status_label
status_label
sort_key_alt
starred
sort_key
contact_presence另,在一帖子上看到Email的URI:
http://www.devdiv.com/thread-50286-1-1.html
content://com.android.email.provider/body
content://com.android.email.provider/message
content://com.android.email.provider/syncedMessage
content://com.android.email.provider/deletedMessage
content://com.android.email.provider/updatedMessage
content://com.android.email.provider/account
content://com.android.email.provider/accountIdAddToField
content://com.android.email.provider/attachment
content://com.android.email.provider/attachment/message
content://com.android.email.provider/mailbox
content://com.android.email.provider/mailboxIdAddToField
content://com.android.email.provider/hostauth觉得这个比较靠谱,但是,在运行程序的时候总报没有权限(permission):
ERROR/AndroidRuntime(2341): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.SocketTest}: java.lang.SecurityException: Permission Denial: opening provider com.android.email.provider.EmailProvider from ProcessRecord{407b8460 2341:com.test/10030} (pid=2341, uid=10030) requires com.android.email.permission.ACCESS_PROVIDER or com.android.email.permission.ACCESS_PROVIDER
不知何故??