简体   繁体   English

仅读取真实联系人

[英]Reading only real contacts

I have a program which reads the contacts and then displays it into the ListView . 我有一个程序,可以读取联系人,然后将其显示在ListView But the problem is that I have total 25k + contacts in my phone and 60% contacts are of google. 但是问题是我的手机中总共有25k +联系人,而Google中有60%的联系人。 So it takes too much time to read contacts. 因此,读取联系人需要太多时间。 How do I read contacts having phone number ? 如何阅读具有电话号码的联系人?

I'm using this code : 我正在使用此代码:

 Cursor phones = as.getApplicationContext().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
   String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));


}
phones.close();

Where clause can be used to filter the contacts with the phone numbers. where子句可用于过滤带有电话号码的联系人。 Use the below code to retrieve the contacts. 使用以下代码检索联系人。

   CursorLoader cursorLoader = new CursorLoader(getActivity(), ContactsContract.Contacts.CONTENT_URI, new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME},
            ContactsContract.Contacts.HAS_PHONE_NUMBER + " > 0 ", null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE ASC;");

For reading the contacts you need the following permission. 要阅读联系人,您需要具有以下权限。

<uses-permission android:name="android.permission.READ_CONTACTS" />

You can use HAS_PHONE_NUMBER. 您可以使用HAS_PHONE_NUMBER。 ContactsContract.Contacts.HAS_PHONE_NUMBER . ContactsContract.Contacts.HAS_PHONE_NUMBER An Example 一个例子

  String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

    if (hasPhone.equals(ContactsContract.Contacts.HAS_PHONE_NUMBER))
      //do your thing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM