简体   繁体   English

在Android中读取联系人并将其写入XML文件

[英]Reading Contacts in Android and writing them onto an XML file

Hello I would like a detailed explanation or an example of retrieving two details in the android contact list(name and Number). 您好,我想要详细的解释或在android联系人列表中检索两个详细信息的示例(姓名和电话号码)。 Once I receive these details I want to write them onto a XML file. 收到这些详细信息后,我想将它们写入XML文件。 As I need to send this XML file to a php server. 因为我需要将此XML文件发送到php服务器。

I know the permission required to do this is 我知道执行此操作所需的权限是

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

and I need to work with Android Cursor and ContactsContract to do this. 并且我需要使用Android CursorContactsContract来执行此操作。 But am not being able to find a good example to do the same. 但是我无法找到一个很好的例子来做同样的事情。 If any one could provide a good pointer or a detailed example of what am looking for it will be highly appreciated. 如果有人可以提供一个很好的指针或所寻找内容的详细示例,将不胜感激。 Thanks in advance. 提前致谢。

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

} }

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM