2009-10-13 7 views
0

나는 모든 연락처와 그 값을 안드로이드 주소록에서 읽는 응용 프로그램을 만들었지 만 모든 연락처를 읽을 수는 없습니다. 현재 이름과 휴대 전화 번호 만 표시됩니다.연락처의 모든 값을 읽을 수 없습니다.

어떻게 모든 전화 번호, 모든 eamil 값 및 주소 값을 얻을 수 있습니까?

미리 감사드립니다 ...

+0

당신은 무엇을 시도 했습니까? –

+0

내 응용 프로그램에서 연락처 세부 정보를 읽으려고합니다. 나는 커서 객체를 가지고있다. 연락처의 모든 세부 사항을 어떻게 찾을 수 있습니까? 연락처를 동기화하고 싶습니다. – Rishabh

+0

Uri contacts = Uri.parse ("content : // contacts/people"); 커서 cur = managedQuery (contacts, projection, null, null, null); if (cur.moveToFirst()) {String name; String phoneNumber; int nameColumn = cur.getColumnIndex (People.NAME); int phoneColumn = cur.getColumnIndex (People.NUMBER); do { name = cur.getString (nameColumn); phoneNumber = cur.getString (phoneColumn); } while (cur.moveToNext()); } – Rishabh

답변

0

우선 댓글에 코드를 넣지 마십시오. 원본 게시물을 편집하면 훨씬 쉽게 읽을 수 있습니다.

두 번째로 Android에서 다소 복잡한 문제입니다. 연락처 정보가 모두 같은 장소에있는 것은 아니므로 원하는 경우 모두입니다. 여러 검색어를 실행해야합니다.

void trythiscode(){ 
    // An array specifying which columns to return. 
    String[] projection = new String[] { 
    People._ID, 
    People.NAME, 
    People.NUMBER, 
}; 

    // Get the base URI for People table in Contacts content provider. 
    // which is: content://contacts/people/ 
    Uri contactUri = People.CONTENT_URI; 

    // Best way to retrieve a query; returns a managed query. 
    Cursor peopleCursor = managedQuery (contactUri, 
    projection, //Which columns to return. 
    null, // WHERE clause--we won't specify. 
    null, // Selection Args?? 
    People.DEFAULT_SORT_ORDER); // Order-by name 

    // go to the beginning of the list 
    peopleCursor.moveToFirst(); 


    // So, here we have a contact. We need to get the contact ID (_id) then 
    // build the Uri to get the phones section of that user's record 
    // which is a subdirectory of a contact record 

    long personId = peopleCursor.getLong(peopleCursor.getColumnIndex("_id")); 

    Uri personUri = ContentUris.withAppendedId(contactUri, personId); 

    // So now the URL looks like: content://contacts/people/_id(where the actual id of the record is here) 
    Uri phoneUri= 
    Uri.withAppendedPath(personUri, Contacts.People.Phones.CONTENT_DIRECTORY); 

    // Now the URL looks like: content://contacts/people/_id/phones (where phones is literally "phones") 

    // Now get all the phone numbers for this contact 
    Cursor phonesCursor = managedQuery(phoneUri, 
    null, 
    null, 
    null, 
    Phones.DEFAULT_SORT_ORDER); 

    // We now have a cursor for all the phone numbers for that User ID 
    // go to the beginning of the phone list. 
    phonesCursor.moveToFirst(); 


} 

를 그리고 이것이 (내가 그것을 시도하지 않은) 오래된 것이 전적으로 가능 : 다음 this thread에서 잘라 붙여 넣을 모든 전화 번호를 얻기의 예입니다. 도넛에서 물건을 업데이트 한 경우 문서를 읽는 데 시간을 할애해야합니다.

관련 문제