1

您好,我想要一个详细的解释或在 android 联系人列表(姓名和号码)中检索两个详细信息的示例。收到这些详细信息后,我想将它们写入XML文件。因为我需要将此 XML 文件发送到 php 服务器。

我知道这样做所需的权限是

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

我需要使用 AndroidCursorContactsContract做到这一点。但是我无法找到一个很好的例子来做同样的事情。如果有人可以提供一个很好的指针或一个详细的例子来说明正在寻找什么,我们将不胜感激。提前致谢。

4

2 回答 2

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);
}

}

于 2013-05-30T08:00:38.257 回答
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>
于 2013-05-30T08:06:14.360 回答