0

我正在尝试获取列出多个电话号码的联系人。我已经开始了一项活动并必须选择一个联系人,但现在我想向用户展示以选择列出更多电话的特定联系人的电话。我已经设法从所有联系人的电话列表中进行选择,但我想先选择一个联系人,然后再选择电话号码。

我如何做到这一点?我应该为此开始一项新活动吗?

谢谢你。

4

1 回答 1

1

你可以尝试类似android_contact_picker

示例用法:

如果您只想从应用程序中打开联系人选择器然后获取号码,请执行以下操作:

private static final int GET_PHONE_NUMBER = 3007;

public void getContact() {
    startActivityForResult(new Intent(this, ContactsPickerActivity.class), GET_PHONE_NUMBER);
}

// Listen for results.
@Override  
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    // See which child activity is calling us back.
    switch (requestCode) {
        case GET_PHONE_NUMBER:
            // This is the standard resultCode that is sent back if the
            // activity crashed or didn't doesn't supply an explicit result.
            if (resultCode == RESULT_CANCELED){
                Toast.makeText(this, "No phone number found", Toast.LENGTH_SHORT).show();
            } 
            else {
                String phoneNumber = (String) data.getExtras().get(ContactsPickerActivity.KEY_PHONE_NUMBER);  
                //Do what you wish to do with phoneNumber e.g.
                //Toast.makeText(this, "Phone number found: " + phoneNumber , Toast.LENGTH_SHORT).show();
            }
        default:
            break;
    }
}
于 2013-01-03T19:04:34.037 回答