使用联系人选取器时,从用户使用多个号码中选择一个号码 [英] Selecting a number from user with multiple numbers when using the contact picker

查看:152
本文介绍了使用联系人选取器时,从用户使用多个号码中选择一个号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户从使用联系人选择器联系人选择电话号码。但是,现在我看到网上的例子告诉你如何选择一个联系人,但我希望能有第二个屏幕,然后弹出如果该联系人有多个电话号码,以便您可以指定要选择(的方式哪一个这短信让你做,所以当你选择一个联系人)。

I'm trying to allow a user to select a phone number from a contact using the contact picker. However, right now all the examples I see online show how you can select a contact, but I am hoping to have a second screen then pop up if that contact has multiple phone numbers so you can specify which one you want to select (the way that text message lets you do so when you select a contact).

我的问题是,你必须收集所有的数字,然后要求用户选择一个数字,或者是这个功能已经内置到Android的?我希望我只是忘了一个标志什么的。

My question is, do you have to gather all of the numbers and then ask the user to select a number, or is this functionality already built into Android? I'm hoping I just forgot a flag or something.

推荐答案

另外,您也可以初步显示与联系人选择器的每个联系人,然后选择一个方式相关联的电话号码。启动联系人选取器这种方式(注意不同的URI比我其他的答案):

Alternatively, you can initially display the phone numbers associated with each contact in the Contact Picker and select one that way. Launch contact picker this way (note the different URI than my other answer):

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(intent, REQUEST_PICK_CONTACT);

然后,在onActivityResult():

Then, in onActivityResult():

Uri result = data.getData();
Log.v(TAG, "Got a result: " + result.toString());

// get the phone number id from the Uri
String id = result.getLastPathSegment();

// query the phone numbers for the selected phone number id
Cursor c = getContentResolver().query(
    Phone.CONTENT_URI, null,
    Phone._ID + "=?",
    new String[]{id}, null);

int phoneIdx = c.getColumnIndex(Phone.NUMBER);

if(c.getCount() == 1) { // contact has a single phone number
    // get the only phone number
    if(c.moveToFirst()) {
        phone = c.getString(phoneIdx);
        Log.v(TAG, "Got phone number: " + phone);

        loadContactInfo(phone); // do something with the phone number

    } else {
        Log.w(TAG, "No results");
    }
}

这篇关于使用联系人选取器时,从用户使用多个号码中选择一个号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆