开发者

Have user pick a contact and get the contact's mobile number

开发者 https://www.devze.com 2023-03-29 19:22 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消