一个查询中的多个联系电话查找

时间:2011-12-18 22:55:59

标签: android sqlite

是否可以在单个查询中搜索包含电话号码列表的联系信息(姓名,照片)?例如:

SELECT name, photo
FROM contacts
WHERE phonenumber IN ("0123456", "987812", "365463")

目前,我在一个包含许多查询的循环中检索联系信息,但这很慢:

String[] phonenumbers = new String[]{"03012345", "04012345", "089012551"};
String[] projection = new String[]{PhoneLookup.DISPLAY_NAME, PhoneLookup._ID};

for (int i = 0; i < phonenumbers.length; i++) {

    // Retrieve name and contact id
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, phonenumbers[i]);
    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
    String name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
    long id = cursor.getLong(cursor.getColumnIndex(PhoneLookup._ID));

    // retrieve photo bitmap with contact id
    uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
    InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), uri);
    Bitmap photo = BitmapFactory.decodeStream(input);
}

0 个答案:

没有答案