Несколько обращений к контактному телефону в одном запросе - PullRequest
3 голосов
/ 19 декабря 2011

Можно ли искать контактную информацию (имя, фото) по списку телефонных номеров в одном запросе? Например:

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);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...