android – 在使用联系人选择器时从多个数字的用户中选择一个数字

我试图允许用户使用联系人选择器从联系人中选择一个电话号码.然而,现在我在网上看到的所有例子都显示了如何选择一个联系人,但是我希望有一个第二个屏幕然后弹出如果该联系人有多个电话号码,以便您可以指定要选择哪一个(方式当您选择联系人时,该文本消息可以让您这样做).

我的问题是,你必须收集所有的数字,然后要求用户选择一个数字,还是这个功能已经内置到Android中?我希望我只是忘了一个国旗或东西.

解决方法

或者,您可以在联系人选择器中最初显示与每个联系人相关联的电话号码,然后选择一个.以这种方式启动联系人选择器(注意不同的URI比我的其他答案):
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(intent,REQUEST_PICK_CONTACT);

然后,在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");
    }
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...