Read all contacts from phone and sim Android

后端 未结 1 702
自闭症患者
自闭症患者 2021-01-12 14:48

EDIT ::: The code works. It was a problem with Eclipse, and the code displays the output in logcat as intended.

Android 2.3.3

I am pretty new to using conten

相关标签:
1条回答
  • 2021-01-12 15:40

    try this

    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 
    
    while (cursor.moveToNext()) {
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
        String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        System.out.println(contactId + "   " + name);
    }
    cursor.close();
    

    it returns the contact's name and the id (the id is probably the row number of the contacts table)

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