2013-05-30 40 views
1

你好,我想詳細解釋一個例子或在android聯繫人列表(姓名和號碼)中檢索兩個細節。一旦我收到這些細節,我想把它們寫到一個XML文件中。因爲我需要將這個XML文件發送到一個PHP服務器。在Android中讀取聯繫人並將它們寫入XML文件

我知道要做到這一點所需的權限

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

,我需要與Android 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文件中採取上述控制措施。並按照下面的描述放置代碼。 –

相關問題