无法检索联系人的电子邮件 [英] Cannot retrieve email from Contacts

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

问题描述

我想从我的电话簿检索电子邮件,电话号码,联系人姓名和列表视图中显示。

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

的名称和号码来了​​完美的,但邮件没有检索。

The name and numbers are coming perfectly but the emails are not retrieving.

下面是相关code:

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();

         }

我知道这个问题已经被问previously但没有一个解决方案已经工作了me.So任何人可以点我出了错误,我在这里做什么?

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的code解决了这个问题。

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天全站免登陆