Reading all contact data

前端 未结 1 1521
野趣味
野趣味 2020-12-31 19:19

I am on Android 2.3.3, API Level 10. I want to read all contacts and data associated to them, therefore e.g. all email addresses, phone numbers, custom fields... I tried it

1条回答
  •  囚心锁ツ
    2020-12-31 19:47

    See Contact Contract API examples

    http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/

    ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);
        if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            String id = cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts._ID));
        String name = cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
            //Query phone here.  Covered next
            }
            }
    }
    }
    

    Take a look at this example

    http://code.google.com/p/android-contacts-contract-example/

    0 讨论(0)
提交回复
热议问题