fsdf fsd fsdf fsd - 5 months ago 22
Android Question

android get all contacts

how can i get all the names of the contacts in my android and put them into array of strings?

Answer

Try this too,

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 (cur.getInt(cur.getColumnIndex(
                    ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
            Cursor pCur = cr.query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    null,
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                    new String[]{id}, null);
            while (pCur.moveToNext()) {
                String phoneNo = pCur.getString(pCur.getColumnIndex(
                        ContactsContract.CommonDataKinds.Phone.NUMBER));
                Toast.makeText(NativeContentProvider.this, "Name: " + name 
                        + ", Phone No: " + phoneNo, Toast.LENGTH_SHORT).show();
            }
            pCur.close();
        }
    }
}

If you need more reference means refer this link Read ContactList

Comments