1

Hello I would like a detailed explanation or an example of retrieving two details in the android contact list(name and Number). Once I receive these details I want to write them onto a XML file. As I need to send this XML file to a php server.

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

D'yer Mak'er
  • 1,632
  • 5
  • 24
  • 47

2 Answers2

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

}

Dharmik Mavani
  • 107
  • 1
  • 8
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>
Dharmik Mavani
  • 107
  • 1
  • 8