android-获取原始联系人缩略图

android-获取原始联系人缩略图,第1张

概述我正在尝试检索原始联系人的照片.我可以成功获取给定原始联系人的高分辨率照片,但是当我想获取同一原始联系人的缩略图时,出现以下异常:02-1705:43:44.695:E/DatabaseUtils(4071):Writingexceptiontoparcel02-1705:43:44.695:E/DatabaseUtils(4071):java.lang.IllegalAr

我正在尝试检索原始联系人的照片.我可以成功获取给定原始联系人的高分辨率照片,但是当我想获取同一原始联系人的缩略图时,出现以下异常:

02-17 05:43:44.695: E/DatabaseUtils(4071): Writing exception to parcel02-17 05:43:44.695: E/DatabaseUtils(4071): java.lang.IllegalArgumentException: URI: content://com.androID.contacts/raw_contacts/8/photo, calling user: com.pedro.notesquirrel, calling package:com.pedro.notesquirrel02-17 05:43:44.695: E/DatabaseUtils(4071):  at com.androID.provIDers.contacts.LegacyAPISupport.query(LegacyAPISupport.java:1914)02-17 05:43:44.695: E/DatabaseUtils(4071):  at com.androID.provIDers.contacts.ContactsProvIDer2.queryLocal(ContactsProvIDer2.java:6378)02-17 05:43:44.695: E/DatabaseUtils(4071):  at com.androID.provIDers.contacts.ContactsProvIDer2.query(ContactsProvIDer2.java:4999)02-17 05:43:44.695: E/DatabaseUtils(4071):  at androID.content.ContentProvIDer$Transport.query(ContentProvIDer.java:200)02-17 05:43:44.695: E/DatabaseUtils(4071):  at androID.content.ContentProvIDerNative.onTransact(ContentProvIDerNative.java:112)02-17 05:43:44.695: E/DatabaseUtils(4071):  at androID.os.Binder.execTransact(Binder.java:404)02-17 05:43:44.695: E/DatabaseUtils(4071):  at dalvik.system.NativeStart.run(Native Method)

我正在使用RESTlet框架,但我认为这与此问题无关.

这是我的代码:

这里mHighResolution是一个布尔值,如果为false,它将生成该异常.正确时将显示照片.
所以,

mHighResolution == false -> exceptionmHighResolution == true -> works fine
public inputStream getPhotoinputStream() {        Uri uri = Uri.withAppendedpath(ContactsContract.RawContacts.CONTENT_URI, String.valueOf(mRawContactID));        return ContactsContract.Contacts.openContactPhotoinputStream(contentResolver, uri, mHighResolution);}
    @OverrIDe    public voID handle(Request request, Response response) {        String type = request.getmethod().getname();        String uID = (String) request.getAttributes().get("uID");        if(type.equalsIgnoreCase("get"))        {            try {                Representation r = processGet(uID);                response.setEntity(r);            } catch (NotFoundException e) {                Log.e(TAG, e.getMessage(), e);                response.setStatus(new Status(Status.CLIENT_ERROR_NOT_FOUND, e.getMessage()));            } catch (IOException e) {                Log.e(TAG, e.getMessage(), e);                response.setStatus(new Status(Status.SERVER_ERROR_INTERNAL, e.getMessage()));                       }         }
private Representation processGet(String uID) throws NotFoundException, IOException{    Photo photo = new Photo(mContext, uID);    Representation representation = new inputRepresentation(photo.getPhotoinputStream());    return representation;}

解决方法:

缩略图照片将从联系人数据库保存在数据表中.

AndroID将照片保存为图像文件(高分辨率)或数据库中的斑点

要访问图像文件,可以使用我在问题中使用的方法.要访问数据库中的缩略图,可以使用以下代码:

public inputStream getPhotothumbnailinputStream(String uID){    final String[] projection = new String[]{Data.DATA15};    final String selection = Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + " =?";    final String[] selectionArgs = new String[]{uID, androID.provIDer.ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE};    final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projection, selection, selectionArgs, null);    if(cursor.movetoFirst())    {        byte[] photo = cursor.getBlob(0);        inputStream is = new ByteArrayinputStream(photo);        cursor.close();        return is;    }    else {        Log.e(TAG, "Photo thumbnail not found for the given raw contact ID.");        cursor.close();        return null;    }}
总结

以上是内存溢出为你收集整理的android-获取原始联系人缩略图全部内容,希望文章能够帮你解决android-获取原始联系人缩略图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1077072.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存