ContactPicker过滤 [英] ContactPicker filtered

查看:153
本文介绍了ContactPicker过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个简单的Andr​​oid应用程序,我需要使用联系人选择器从地址簿中获得的电话号码。

In a simple Android App I need to get phone number from Address Book using Contacts picker.

要打开联系人选择器我用以下code:

To open Contact picker I use following code:

            Intent intent = new Intent(Intent.ACTION_PICK,
                    ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(intent, PICK_CONTACT);

所有工作正常,但在通讯录中选择器,我可以从Gmail中查看联系人,如果我在手机应用程序我只看到Addess本书的联系人使用联系人选择器。我怎么可以显示联系人选择器作为手机应用程序(不包括Gmail联系人)?

All works fine but in Contacts Picker I can see contacts from gmail, if I use Contact Picker in Phone App I see only Addess book's contacts. How can I show a Contact Picker as Phone App (without gmail contacts)?

推荐答案

这帮助我只是过滤电话号码:

This helped me Filter just for phone numbers:

Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
        ArrayList<String> phoneNumber = new ArrayList<String>();
        while (cursor.moveToNext()) {
            String contactId = cursor.getString(cursor
                    .getColumnIndex(ContactsContract.Contacts._ID));

            String name = cursor
                    .getString(cursor
                            .getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
            phoneNumber.add(name);
            String hasPhone = cursor
                    .getString(cursor
                            .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

            if (hasPhone.equalsIgnoreCase("1")) {
                hasPhone = "true";
            } else {
                hasPhone = "false";
            }

            if (Boolean.parseBoolean(hasPhone)) {
                Cursor phones = null;

                phones = getContentResolver().query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                + " = " + contactId, null, null);

                while (phones.moveToNext()) {

                    phoneNumber
                            .add(phones.getString(phones
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));

                }
                phones.close();
            }
        }
        cursor.close();

这篇关于ContactPicker过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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