在自己的应用中使用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" />,但确实是添了的。

解决方案 »

  1.   

    URI:
    2.x:content://com.android.contacts/data/emails
    1.6:Contacts.ContactMethods.CONTENT_URI
      

  2.   

    谢谢dinjay的回复,按照你的提示换成content://com.android.contacts/data/emails的uri确实不出错了,感谢中...
    但还有一个问题请问,若是按照此uri访问那么访问的数据库还是data/data/com.android.eamil/databases/EmailProvider.db吗,我要再继续访问里面的表message或account数据那么此uri后面还需要添/message与/account吗?若不是此数据库文件那么又是哪个呢?
      

  3.   

    刚才我又用代码测试了读出数据库的columns,感觉里面的内容是联系人信息里面的email地址信息,不知道dinjay是否是这个意思,其实我想要读取的发送或接收的电子邮件内容信息。
    还是要谢谢您的帮助!
      

  4.   

    Email的数据库你是没办法直接这样查询的,你是要获取什么东西,Message内容吗?说清楚一些,有办法搞定的
      

  5.   

    按照content://com.android.contacts/data/emails打开的cursor有getcolumname函数,可以遍历一下有那些数据可以获取,会有很多。
      

  6.   

    回复SunZhanwei:其实我是想读出电邮的基本信息(发送或接收地址、主题等)以列表的形式显示出来,根据用户的选择后再显示其详细信息。通话记录与短信的都已经实现了就只剩下电邮的访问一直未成功,查询android的源代码也没有发现解决办法。您要是有什么方法可以取到请方便告之,将不胜感激。回复dinjay:我是用String [] items = cur.getColumnNames();得到的所有columns的,但没有发现我想要的信息的,谢谢关注。
      

  7.   

    没具体获取过
    看看sdk中的
    ContactsContract.CommonDataKinds.Email
      

  8.   


    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邮箱的信息。
      

  9.   

    此问题今天已找到解决办法,其实前段时间应该也是找到了,但因为资源的问题引起应用崩溃未找到原因一直以为是访问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报错了所以也就不介绍了,等解决好了再继续介绍。
    困扰了好久的问题终于解决了希望能对大家都有帮助。
      

  10.   

    导致错误的原因如下:
    因为Android本身自带的email应用的保护级别很高,是android:protectionLevel="signatureOrSystem",从android sdk自带文档了解到此种权限保护级别需要system本身镜像应用或者是同system镜像具有相同的签名应用才可以访问,因此一般的第三方应用即使添加了permission也还是会报错的。
    这个permission我学习过,有四种格式似乎!
      

  11.   

    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. 
      

  12.   

    dinjay:我这里没有真机的sourcecode因此没有办法把应用集成到某款机器上。
    根据SDK的文档和查的资料来讲signatureOrSystem这种权限的应用第三方的应用时无法单独访问的,要么把自己的应用一同生成system.img,要么就得和system.img具有一样的签名。像我这个若单独做个应用的话那么肯定是实现不了的,因为每款机器签名肯定都不一样,解决的办法就是把软件集成到手机厂商的img里面。因此你说的放到真机里面肯定不行的,它不能作为一款第三方软件发布,若将已经集成的img文件重新烧一下手机的话我想应该是可以的了。
      

  13.   

    登录邮箱后导入很多邮件,这部分会进入我的历史记录,我该如何过滤掉这部分?我的代码监看DB,只要email有变化就插入,不知如何区分这部分和在手机上收发的。
      

  14.   

    能提供一份源程序吗???谢谢
    [email protected]
      

  15.   

    兄弟,你确定这是官方SDK中的方法吗?
    我用的是SDK2.3,也查了就没有你这个provider,Email.CONTENT_LOOKUP_URI就更加没有了,直接报错!
      

  16.   

    我按老兄你说的试了下,所得游标字段名如下:
    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
    不知何故??
      

  17.   

    跟帖。能否给我一份源码呢、谢谢你、邮箱是[email protected]