2013-05-30 5 views
1

안녕하세요, Android 연락처 목록 (이름 및 번호)에서 두 가지 세부 정보를 가져 오는 자세한 설명이나 예가 필요합니다. 이러한 세부 정보를 수신하면 XML 파일에 기록하고 싶습니다. 이 XML 파일을 PHP 서버로 보내야합니다.Android에서 연락처 읽기 및 XML 파일에 쓰기

나는이 작업을 수행하는 데 필요한 권한을

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> 

알고 나는이 일을 안드로이드 CursorContactsContract와 함께 작동하도록해야합니다. 그러나 똑같은 일을하는 좋은 모범을 찾을 수 없다. 좋은 포인터를 제공 할 수있는 사람이나 찾고있는 것에 대한 자세한 예제를 제공 할 수 있다면 매우 높이 평가 될 것입니다. 미리 감사드립니다.

답변

0
private void readContacts() { 
    String[] projection = {ContactsContract.Contacts.DISPLAY_NAME}; 
    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, projection, null, null, null); 
    Log.i("Demo", "" + cursor.getCount()); 
    String[] strs = new String[cursor.getCount()]; 
    cursor.moveToFirst(); 
    int i = 0; 
    do { 
     strs[0] = cursor.getString(0); 
    }while (cursor.moveToNext()); 

    ArrayAdapter<String> liststr = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); 
    getListView().setAdapter(liststr); 
} 

}

+0

는 클래스에이 기능을 확인하고 한 OnCreate() 메소드를 호출합니다. –

0
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 
+0

xml 파일에서 위에 언급 된 컨트롤을 가져옵니다. 아래에 설명 된대로 코드를 입력하십시오. –