开发者

Reading contacts in Android

开发者 https://www.devze.com 2023-01-18 15:57 出处:网络
I am writing the program for reading contacts from android.when i am executing the following codeit successfully gets the name but failed to get phone number and showing the ArrayIndexoutofBoundExcept

I am writing the program for reading contacts from android.when i am executing the following code it successfully gets the name but failed to get phone number and showing the ArrayIndexoutofBoundExcepti开发者_Python百科on....The code is

Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

while(people.moveToNext()) 
{
    int nameFieldColumnIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
    String contact = people.getString(nameFieldColumnIndex);
    contactView.append(contact);

    int numberFieldColumnIndex = people.getColumnIndex(PhoneLookup.NUMBER);

    String number = people.getString(numberFieldColumnIndex);
    contactView.append(number);
}


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

boolean hasPhone = (Integer.parseInt(people.getString(
                       people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0);  
 if (hasPhone)  
 {
     Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                   null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", 
                   new String[]{id}, null);
     while (pCur.moveToNext()) {
        // process phone numbers
     } 
     pCur.close();
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消