2
我正在尝试检索原始联系人的照片。我能成功获得高分辨率照片给定的原料接触,但是当我想要得到的缩略图照片相同的原始接触,我得到这个异常:获取Raw联系人缩略图照片
02-17 05:43:44.695: E/DatabaseUtils(4071): Writing exception to parcel
02-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.notesquirrel
02-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
是Boolean
,当它是false
它会生成异常。当它是真的时,它显示照片。 所以,
mHighResolution == false -> exception
mHighResolution == 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;
}