Opencontactphotoinputstream Causes “java.lang.illegalstateexception: Get Field Slot From Row 0 Col 0 Failed”
Background I'm trying to check if a contact image exists for a specific contact (and later to actually get it, much later). the query should be as minimal as possible and avoid un-
Solution 1:
How about something like this for checking if a photo exists (untested):
ContentResolvercr= mContext.getContentResolver();
if (bigPicture && VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
UridisplayPhotoUri= Uri.withAppendedPath(contactUri,
ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
AssetFileDescriptorfd=null;
try {
fd = cr.openAssetFileDescriptor(displayPhotoUri, "r");
} catch (FileNotFoundException e) {}
if (fd != null) {
try {
fd.close();
} catch (IOException e) {
e.printStackTrace();
}
returntrue;
}
}
UriphotoUri= Uri.withAppendedPath(contactUri,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
Cursorcursor= cr.query(photoUri, newString[] {BaseColumns._ID},
ContactsContract.Contacts.Photo.PHOTO + " IS NOT NULL", null, null);
if (cursor == null) {
returnfalse;
}
try {
return cursor.moveToFirst();
} finally {
cursor.close();
}
And here is a modified version of the openContactPhotoInputStream()
method, which should potentially be able to load a photo thumbnail with a size close to 1 MB without issues (again not tested):
publicstatic InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri,
boolean preferHighres) {
if (preferHighres && VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
UridisplayPhotoUri= Uri.withAppendedPath(contactUri,
ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
try {
return cr.openAssetFileDescriptor(displayPhotoUri, "r").createInputStream();
} catch (IOException e) {}
}
UriphotoUri= Uri.withAppendedPath(contactUri,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
try {
return cr.openAssetFileDescriptor(displayPhotoUri, "r").createInputStream();
} catch (IOException e) {}
returnnull;
}
This should cause the ContactsProvider
to read the thumbnail BLOB
to shared memory, and send an AssetFileDescriptor
pointing to it, from which we can directly open an InputStream
.
Post a Comment for "Opencontactphotoinputstream Causes “java.lang.illegalstateexception: Get Field Slot From Row 0 Col 0 Failed”"