Android Contact phone number using Loader Invalid column data1

后端 未结 3 1871
日久生厌
日久生厌 2021-01-14 00:14

I used to use content resolver previously to fetch Contact list and their details while that still works I wanted to try the Loader method which queries the Content Provider

3条回答
  •  -上瘾入骨i
    2021-01-14 00:20

    This is an excerpt of what I actually do in my (working) code.

    These are my relevant imports:

    import android.provider.ContactsContract;
    import android.provider.ContactsContract.CommonDataKinds.Email;
    import android.provider.ContactsContract.CommonDataKinds.Phone;
    import android.provider.ContactsContract.Contacts;
    

    Given that id is a string (representing a number, like "1", "20", ...)

    // Query for phone numbers for the selected contact id
    final Cursor cur = getContentResolver().query
        (
        Phone.CONTENT_URI, null,
        Phone.CONTACT_ID + "=?",
        new String[] {id}, null
        );
    
    final int phoneIdx = cur.getColumnIndex(Phone.NUMBER);
    final int phoneType = cur.getColumnIndex(Phone.TYPE);
    
    // ...
    
        if(cur.moveToFirst())
        {
            final String name =
                cur.getString
                (
                    cur.getColumnIndexOrThrow
                    (
                        ContactsContract.Contacts.DISPLAY_NAME
                    )
                );
        }
    

    Hope it puts you on the right path

提交回复
热议问题