找_ID

2011-08-18 54 views
0

特定聯繫人的所有信息請參閱本來源:找_ID

private void populateContactList() { 
    // Build adapter with contact entries 
    Cursor cursor = getContacts(); 
    /* 
    String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME}; 
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor, 
      fields, new int[] {R.id.contactEntryText}); 
    mContactList.setAdapter(adapter);*/ 

    while(cursor.moveToNext()){ 
     int id = cursor.getInt(0);  
     String nome = cursor.getString(1); 
     Log.i("ContactsTest", id + " - "+ nome); 
    } 

} 

/** 
* Obtains the contact list for the currently selected account. 
* 
* @return A cursor for for accessing the contact list. 
*/ 
private Cursor getContacts() 
{ 
    // Run query 
    // se tem número de telefone 

    Uri uri = ContactsContract.Contacts.CONTENT_URI; 
    String[] projection = new String[] { 
      ContactsContract.Contacts._ID, 
      ContactsContract.Contacts.DISPLAY_NAME, 
      ContactsContract.Contacts.HAS_PHONE_NUMBER,     
    }; 
    //trazer só os contatos que possuem ao menos um número. 
    String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = " + "0"; 
    String[] selectionArgs = null; 
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; 

    return managedQuery(uri, projection, selection, selectionArgs, sortOrder); 
} 

如何獲取一個用戶的所有信息通過_ID內while循環?

你能幫我嗎?

感謝

馬特烏斯·迪亞斯

回答

0

不知道是否有幫助,但這裏是我剪斷使用來獲取所有聯繫人數據

 
android get all contacts 





// 
    // Find contact based on name. 
    // 
    ContentResolver cr = getContentResolver(); 
    Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, 
     "DISPLAY_NAME = '" + NAME + "'", null, null); 
    if (cursor.moveToFirst()) { 
     String contactId = 
      cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); 
     // 
     // Get all phone numbers. 
     // 
     Cursor phones = cr.query(Phone.CONTENT_URI, null, 
      Phone.CONTACT_ID + " = " + contactId, null, null); 
     while (phones.moveToNext()) { 
      String number = phones.getString(phones.getColumnIndex(Phone.NUMBER)); 
      int type = phones.getInt(phones.getColumnIndex(Phone.TYPE)); 
      switch (type) { 
       case Phone.TYPE_HOME: 
        // do something with the Home number here... 
        break; 
       case Phone.TYPE_MOBILE: 
        // do something with the Mobile number here... 
        break; 
       case Phone.TYPE_WORK: 
        // do something with the Work number here... 
        break; 
       } 
     } 
     phones.close(); 
     // 
     // Get all email addresses. 
     // 
     Cursor emails = cr.query(Email.CONTENT_URI, null, 
      Email.CONTACT_ID + " = " + contactId, null, null); 
     while (emails.moveToNext()) { 
      String email = emails.getString(emails.getColumnIndex(Email.DATA)); 
      int type = emails.getInt(emails.getColumnIndex(Phone.TYPE)); 
      switch (type) { 
       case Email.TYPE_HOME: 
        // do something with the Home email here... 
        break; 
       case Email.TYPE_WORK: 
        // do something with the Work email here... 
        break; 
      } 
     } 
     emails.close(); 
    } 
    cursor.close(); 















Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, personId); 
Uri phonesUri = Uri.withAppendedPath(personUri, People.Phones.CONTENT_DIRECTORY); 
String[] proj = new String[] {Phones._ID, Phones.TYPE, Phones.NUMBER, Phones.LABEL} 
Cursor cursor = contentResolver.query(phonesUri, proj, null, null, null);