Skip to content

Commit

Permalink
Making sure Cursor is closed if exception gets thrown.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyr59h committed Apr 23, 2015
1 parent 21508f3 commit d70578c
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,17 @@ public static byte[] createThumbnailFromUri(Context context,
String filePath = null;
if (imageUri.toString().contains("content:")) {
String[] projection = new String[] { MediaStore.Images.Media.DATA };
Cursor cur = null;
try {
Cursor cur = context.getContentResolver().query(imageUri, projection, null, null, null);
if (cur != null) {
if (cur.moveToFirst()) {
int dataColumn = cur.getColumnIndex(MediaStore.Images.Media.DATA);
filePath = cur.getString(dataColumn);
}
cur.close();
cur = context.getContentResolver().query(imageUri, projection, null, null, null);
if (cur != null && cur.moveToFirst()) {
int dataColumn = cur.getColumnIndex(MediaStore.Images.Media.DATA);
filePath = cur.getString(dataColumn);
}
} catch (IllegalStateException stateException) {
Log.d(ImageUtils.class.getName(), "IllegalStateException querying content:" + imageUri);
} finally {
SqlUtils.closeCursor(cur);
}
}

Expand Down

0 comments on commit d70578c

Please sign in to comment.