让用户选择一个联系人并获取该联系人的手机号码

发布于 2024-11-30 18:04:50 字数 1071 浏览 0 评论 0原文

我试图让用户从他的联系人列表中选择一个联系人,以便我可以对该号码进行一些处理。我启动列表选择活动的代码是

    Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,  
            Contacts.Phones.CONTENT_URI);  
    startActivityForResult(contactPickerIntent, PICK_CONTACT);

,我的接收代码是,

@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 result: "  
                + result.toString());  
        }
    break;
    }
}

但额外捆绑包中没有任何姓名或电话号码。如何获取用户选择的结果?

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 result: "  
                + 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2024-12-07 18:04:50

getData() 调用包含可在其上打开游标的 Uri。请尝试以下操作:

   Uri resultUri = data.getData();
   Cursor cursor =  managedQuery(resultUri, null, null, null, null);
   if (cursor.moveToFirst()) {
       // Found results process cursor
   }

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
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文