开发者

get current contacts in android

I know that there been alot of questions about this issue. but I can't found nothing that help me. I know how to get all android contacts that have phone number by this code:

private List fillContactsList() {
        List tmpList = new ArrayList();

        Cursor c = getContentResolver().query(
                ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        while (c.moveToNext()) {
            String ContactID = c.getString(c
                    .getColumnIndex(ContactsContract.Contacts._ID));
            String name = c.getString(c
                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            String hasPhone = c
                    .getString(c
                            .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
            if (Integer.parseInt(hasPhone) == 1) {
                Cursor phoneCursor = getContentResolver().query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                + "='" + ContactID + "'", null, null);
                while (phoneCursor.moveToNext()) {
                    String number = phoneCursor
                            .getString(phoneCursor
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    con = new Contact();
                    con.setName(name);
     开发者_StackOverflow中文版               con.setNumber(number);
                    tmpList.add(con);
                }
                phoneCursor.close();
            }
        }
        c.close();
        Collections.sort(tmpList);

        return tmpList;
    }

The result of this on my device is 360 contacts but when I open my contact via the phone I see just 120. so How can I get just the group that currently showing on the contacts list on the phone?

Thanks! Saar


I don't know if this is your problem or not, but you could try adding IN_VISIBLE_GROUP to your selection criteria. I don't remember the exact syntax off the top of my head, but it'd be something like this:

Cursor c = getContentResolver().query(
               ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'", null, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜