如何在Android中从手机中获取不同的联系人

时间:2015-11-03 05:40:19

标签: java android

我想从手机上获取独特的联系人;现在它显示重复。它正在获取手机通讯录,SIM卡联系人以及Gmail帐户联系人。

public void readContacts() {

    name.clear();
    number.clear();

    content_resolver = getContentResolver();
    cursor = content_resolver.query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
            null, null);

    if (cursor != null) {
        cursor.moveToFirst();
        do {
            number.add(cursor.getString(cursor
                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
            name.add(cursor.getString(cursor
                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
        } while (cursor.moveToNext());
    }

    simCursor = this.getContentResolver().query(simUri, null, null, null,
            null);
    if (simCursor.moveToFirst()) {
        do {
            number.add(simCursor.getString(simCursor
                    .getColumnIndex("number")));
            name.add(simCursor.getString(simCursor.getColumnIndex("name")));
        } while (simCursor.moveToNext());
    }

    // ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
}

0 个答案:

没有答案