Reputation: 29
I am using this code below to pick a contact number , but some contacts have more than one number, how can I select one of the contact numbers?
Cselect.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 0);
}
});
Upvotes: 0
Views: 395
Reputation: 2843
In the result, you should get a Uri. From this, you will be able to grab a Cursor, and then iterate over the cursor to grab the information you require. I would advise you dump the cursor into the Logs so you can see what is returned, by using the DatabaseUtils
class.
The following is a snippet of how you can retrieve the Cursor and iterate over it:
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
txtContacts.setText(name);
}
}
Upvotes: 1