gpt4 book ai didi

Android 联系人在一次查询中获取照片缩略图

转载 作者:行者123 更新时间:2023-11-29 18:58:08 25 4
gpt4 key购买 nike

我有很多查询,并且花了很多时间来获取联系人数据。因此需要将所有查询转换为一个。

我在一次查询中获得了所有其他信息,例如显示名称、手机号码、标签、电子邮件但只有通过拍照才能发现问题

帮我将下面的照片查询转换为单个查询并获取图片的 uri :

ContentResolver KntRslverVar = getContentResolver();
Cursor ContctKsrVar = KntRslverVar.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER},
null, null, null);

while (ContctKsrVar.moveToNext())
{
String ContctUidVar = ContctKsrVar.getString(ContctKsrVar.getColumnIndex(ContactsContract.Contacts._ID));
String ContctNamVar = ContctKsrVar.getString(ContctKsrVar.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String ContctMobVar = ContctKsrVar.getString(ContctKsrVar.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

Cursor ContctPflPicKsrVar = KntRslverVar.query(
ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?",
new String[]{ContctUidVar, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE},
null);

if (ContctPflPicKsrVar != null && ContctPflPicKsrVar.getCount() > 0)
{
while(ContctPflPicKsrVar.moveToNext())
{
Uri ContctPflPicUriVar = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(ContctUidVar));
PflPicUriVar = Uri.withAppendedPath(ContctPflPicUriVar, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}
ContctPflPicKsrVar.close();
}
}

尝试1:

 Cursor ContctKsrVar = KntRslverVar.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE},
null, null, null);

尝试 2:

Cursor ContctKsrVar = KntRslverVar.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI},
null, null, null);

还需要从获取的查询中获取 uri 的帮助:

Uri KctPflPicUriVar = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(KctUidVar));
PflPicUriVar = Uri.withAppendedPath(KctPflPicUriVar, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

最佳答案

|*|优化:在一次查询中获取显示名称和号码以及标签和照片缩略图:在 4 秒内获取结果查询。

ContentResolver contntRslverVar = getContentResolver();
Cursor contctKsrVar = contntRslverVar.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI},
null, null, null);

while (contctKsrVar.moveToNext())
{
String contctUidVar = contctKsrVar.getString(contctKsrVar.getColumnIndex(ContactsContract.Contacts._ID));
String contctNamVar = contctKsrVar.getString(contctKsrVar.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String contctMobVar = contctKsrVar.getString(contctKsrVar.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

int MobLblTypVar = contctKsrVar.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
int MobLblTipVar = contctKsrVar.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL);
MobLblTypVar = contctKsrVar.getInt(MobLblTypVar);

String contctMobLblVar;
if(MobLblTypVar == ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM)
{
contctMobLblVar = contctKsrVar.getString(MobLblTipVar);
}
else
{
CharSequence MobLblSrgVar = ContactsContract.CommonDataKinds.Phone.getTypeLabel(getResources(), MobLblTypVar, "Mobile");
contctMobLblVar = MobLblSrgVar.toString();
}

String PflPicSrgVar = contctKsrVar.getString(contctKsrVar.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI));
if(PflPicSrgVar != null) Uri PflPicUriVar = Uri.parse(PflPicSrgVar);
}

关于Android 联系人在一次查询中获取照片缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44034741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com