使用联系人选取器时,从用户使用多个号码中选择一个号码号码、多个、联系人、用户

由网友(君悦君兮君不知)分享简介:我试图让用户从使用联系人选择器联系人选择电话号码。但是,现在我看到网上的例子告诉你如何选择一个联系人,但我希望能有第二个屏幕,然后弹出如果该联系人有多个电话号码,以便您可以指定要选择(的方式哪一个这短信让你做,所以当你选择一个联系人)。 I'm trying to allow a user to select a p...

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

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");
    }
}
阅读全文

相关推荐

最新文章