Reading contacts in Android

前端 未结 1 1543
傲寒
傲寒 2021-01-24 08:22

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

1条回答
  •  一向
    一向 (楼主)
    2021-01-24 08:44

    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 讨论(0)
提交回复
热议问题