无法从通讯录中检索电子邮件 [英] Cannot retrieve email from Contacts

查看:25
本文介绍了无法从通讯录中检索电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的电话簿中检索电子邮件、电话号码和联系人姓名,并将它们显示在列表视图中.

I want to retrieve email,phone number and contact names from my phone-book and display them in list-view.

姓名和号码准确无误但电子邮件无法检索.

相关代码如下:

public  void getAllContacts(ContentResolver cr) {
          String email="";
            Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, Phone.DISPLAY_NAME + " ASC");
            //email = new String[phones.getCount()];

            while (phones.moveToNext())
            {
              String id = phones.getString(phones.getColumnIndex(ContactsContract.Contacts._ID));
              String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
              String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
              System.out.println("name.................."+name+"........number......."+phoneNumber); 

              name1.add(name);
              phno1.add(phoneNumber);

             Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{id}, null);
             if(emailCur!=null)
             {
                 emailCur.moveToFirst();
             }
            // emailCur.moveToFirst();
              while (emailCur.moveToNext()) { 

                  email = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                  System.out.println(email);
                  } 
                  email1.add(email); 
                  emailCur.close();


            }


            phones.close();

         }

我知道之前有人问过这个问题,但没有一个解决方案对我有用.所以有人能指出我在这里做的错误吗??

I know this question has been asked previously but none of the solutions has worked for me.So can anybody point me out the mistake I am doing here??

推荐答案

我遇到了同样的问题.我通过改变kgandroid的代码解决了

I had the same problem. I solved it by changing kgandroid's code

String id = phones.getString(phones.getColumnIndex(ContactsContract.Contacts._ID));

String id = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));

(注意 ContactsContract.CommonDataKinds.Phone.CONTACT_ID = "contact_id" 而 ContactsContract.Contacts._ID = "_id")

(Note that ContactsContract.CommonDataKinds.Phone.CONTACT_ID = "contact_id" while ContactsContract.Contacts._ID = "_id")

这篇关于无法从通讯录中检索电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆