I'm trying to have a user pick a contact from his contacts list so that I can do some processing on that number. My code to launch the list-picking activity is
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.Phones.CONTENT_URI);
startActivityForResult(contactPickerIntent, PICK_CONTACT);
and my receiving code is
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Set<String> keys = extras.keySet();
Iterator<String> iterate = keys.iterator();
while (iterate.hasNext()) {
String key = iterate.next();
Log.v(TAG, key + "[" + extras.get(key) + "]");
}
Uri result = data.getData();
Log.v(TAG, "Got a res开发者_StackOverflow中文版ult: "
+ result.toString());
}
break;
}
}
but the extras bundle does not have any names or phone numbers in it. How can I get the result of a user's selection?
The getData() call contains the Uri that you can open a cursor on. Try the following:
Uri resultUri = data.getData();
Cursor cursor = managedQuery(resultUri, null, null, null, null);
if (cursor.moveToFirst()) {
// Found results process cursor
}
精彩评论