【问题标题】:android: How to pick contacts phone numandroid:如何选择联系人电话号码
【发布时间】:2012-06-13 12:01:31
【问题描述】:

我需要选择联系电话号码,我曾经这样做过......

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(意图,GET_CONTACT_FROM_RESULT);

但是,当一个联系人有多个号码时,pick Activity 只会列出一个联系人,并且只能选择一个电话。

如何显示联系人的每个电话号码?

【问题讨论】:

    标签: android contacts


    【解决方案1】:

    您可以让联系人选择器在每部手机上显示一个联系人,这样多部手机的联系人就会出现多次:

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
    startActivityForResult(intent, PICK_CONTACT);
    

    【讨论】:

    • 谢谢,我赞成!我怎么知道他们选择了哪些联系人,但我想在共享偏好中分享它。
    【解决方案2】:
     public Map<String, String> lookupPhoneNoAndContactId(){
        Map<String, String> phonenumbers = new HashMap<String, String>();
        Cursor cursor = null;
        try {
            cursor = contentResolver.query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                    null, null, null);
            while (cursor.moveToNext()) {
                phonenumbers
                        .put(cursor
                                .getString(cursor
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)),
                                cursor.getString(cursor
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)));
            }
            return phonenumbers;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-08
      • 1970-01-01
      • 2017-05-28
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 2011-06-11
      相关资源
      最近更新 更多