关于读取email数据库德权限问题

mora 2010-08-19 02:51:14
在自己的应用中使用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" />,但确实是添了的。
...全文
2532 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
门前大桥下 2013-03-14
  • 打赏
  • 举报
回复
跟帖。能否给我一份源码呢、谢谢你、邮箱是88661049@qq.com
「已注销」 2011-12-07
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 mora 的回复:]

好长时间没看此贴了没想到后面还有人跟贴。
真的抱歉几位的源代码要求,因为是公司的项目公司的代码,虽然是我写的和验证的但我也无权泄漏出去。其实我上面已经说明了并不是代码的问题而是权限的问题造成的,只要保证应用能达到访问权限就可以了。
谢谢关注。
[/Quote]

我也要用到啊.真没有其他办法了吗.权限的问题唉.
mora 2011-10-11
  • 打赏
  • 举报
回复
好长时间没看此贴了没想到后面还有人跟贴。
真的抱歉几位的源代码要求,因为是公司的项目公司的代码,虽然是我写的和验证的但我也无权泄漏出去。其实我上面已经说明了并不是代码的问题而是权限的问题造成的,只要保证应用能达到访问权限就可以了。
谢谢关注。
wang_yong 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dinjay 的回复:]
URI:
2.x:content://com.android.contacts/data/emails
1.6:Contacts.ContactMethods.CONTENT_URI
[/Quote]
我按老兄你说的试了下,所得游标字段名如下:
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
不知何故??
wang_yong 2011-05-04
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dinjay 的回复:]
Java code

Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
Cursor c = getContentResolver().query(uri,
new String[]{Email.DISPLAY_NAME, Email.DATA},
……
[/Quote]
兄弟,你确定这是官方SDK中的方法吗?
我用的是SDK2.3,也查了就没有你这个provider,Email.CONTENT_LOOKUP_URI就更加没有了,直接报错!
liuguozhen 2011-01-04
  • 打赏
  • 举报
回复
能提供一份源程序吗???谢谢
liuguozhen-@163.com
jornie 2010-11-26
  • 打赏
  • 举报
回复
楼主,能提供一下你的源代码吗?非常感谢。邮箱:zixiayishi0251094@hotmail.com
wenly8384 2010-11-08
  • 打赏
  • 举报
回复
登录邮箱后导入很多邮件,这部分会进入我的历史记录,我该如何过滤掉这部分?我的代码监看DB,只要email有变化就插入,不知如何区分这部分和在手机上收发的。。。。。。。
dinjay 2010-09-03
  • 打赏
  • 举报
回复
预装....定制手机
mora 2010-09-03
  • 打赏
  • 举报
回复
dinjay:我这里没有真机的sourcecode因此没有办法把应用集成到某款机器上。
根据SDK的文档和查的资料来讲signatureOrSystem这种权限的应用第三方的应用时无法单独访问的,要么把自己的应用一同生成system.img,要么就得和system.img具有一样的签名。像我这个若单独做个应用的话那么肯定是实现不了的,因为每款机器签名肯定都不一样,解决的办法就是把软件集成到手机厂商的img里面。因此你说的放到真机里面肯定不行的,它不能作为一款第三方软件发布,若将已经集成的img文件重新烧一下手机的话我想应该是可以的了。
dinjay 2010-09-03
  • 打赏
  • 举报
回复
LZ,你这样应用放真机上试过么?估计是不行的
纠结的木棉花 2010-09-02
  • 打赏
  • 举报
回复
嗯!不过实际用到的好像不是很多。。。
mora 2010-09-02
  • 打赏
  • 举报
回复
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.
纠结的木棉花 2010-09-02
  • 打赏
  • 举报
回复
导致错误的原因如下:
因为Android本身自带的email应用的保护级别很高,是android:protectionLevel="signatureOrSystem",从android sdk自带文档了解到此种权限保护级别需要system本身镜像应用或者是同system镜像具有相同的签名应用才可以访问,因此一般的第三方应用即使添加了permission也还是会报错的。
这个permission我学习过,有四种格式似乎!
mora 2010-09-02
  • 打赏
  • 举报
回复
此问题今天已找到解决办法,其实前段时间应该也是找到了,但因为资源的问题引起应用崩溃未找到原因一直以为是访问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报错了所以也就不介绍了,等解决好了再继续介绍。
困扰了好久的问题终于解决了希望能对大家都有帮助。
godasd 2010-08-25
  • 打赏
  • 举报
回复
我也存在相同问题求解答
mora 2010-08-20
  • 打赏
  • 举报
回复
自己顶下,还有人会吗?
dinjay 2010-08-20
  • 打赏
  • 举报
回复

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邮箱的信息。
dinjay 2010-08-20
  • 打赏
  • 举报
回复
没具体获取过
看看sdk中的
ContactsContract.CommonDataKinds.Email
mora 2010-08-19
  • 打赏
  • 举报
回复
回复SunZhanwei:其实我是想读出电邮的基本信息(发送或接收地址、主题等)以列表的形式显示出来,根据用户的选择后再显示其详细信息。通话记录与短信的都已经实现了就只剩下电邮的访问一直未成功,查询android的源代码也没有发现解决办法。您要是有什么方法可以取到请方便告之,将不胜感激。

回复dinjay:我是用String [] items = cur.getColumnNames();得到的所有columns的,但没有发现我想要的信息的,谢谢关注。
加载更多回复(5)

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧