1919import android .os .AsyncTask ;
2020import android .provider .MediaStore ;
2121import android .text .TextUtils ;
22+ import android .util .Log ;
2223import android .widget .ImageView ;
2324
2425import org .apache .http .HttpEntity ;
@@ -42,13 +43,17 @@ public static int[] getImageSize(Uri uri, Context context){
4243
4344 if (uri .toString ().contains ("content:" )) {
4445 String [] projection = new String [] { MediaStore .Images .Media ._ID , MediaStore .Images .Media .DATA };
45- Cursor cur = context .getContentResolver ().query (uri , projection , null , null , null );
46- if (cur != null ) {
47- if (cur .moveToFirst ()) {
46+ Cursor cur = null ;
47+ try {
48+ cur = context .getContentResolver ().query (uri , projection , null , null , null );
49+ if (cur != null && cur .moveToFirst ()) {
4850 int dataColumn = cur .getColumnIndex (MediaStore .Images .Media .DATA );
4951 path = cur .getString (dataColumn );
5052 }
51- cur .close ();
53+ } catch (IllegalStateException stateException ) {
54+ Log .d (ImageUtils .class .getName (), "IllegalStateException querying content:" + uri );
55+ } finally {
56+ SqlUtils .closeCursor (cur );
5257 }
5358 }
5459
@@ -406,13 +411,17 @@ public static byte[] createThumbnailFromUri(Context context,
406411 String filePath = null ;
407412 if (imageUri .toString ().contains ("content:" )) {
408413 String [] projection = new String [] { MediaStore .Images .Media .DATA };
409- Cursor cur = context .getContentResolver ().query (imageUri , projection , null , null , null );
410- if (cur != null ) {
411- if (cur .moveToFirst ()) {
414+ Cursor cur = null ;
415+ try {
416+ cur = context .getContentResolver ().query (imageUri , projection , null , null , null );
417+ if (cur != null && cur .moveToFirst ()) {
412418 int dataColumn = cur .getColumnIndex (MediaStore .Images .Media .DATA );
413419 filePath = cur .getString (dataColumn );
414420 }
415- cur .close ();
421+ } catch (IllegalStateException stateException ) {
422+ Log .d (ImageUtils .class .getName (), "IllegalStateException querying content:" + imageUri );
423+ } finally {
424+ SqlUtils .closeCursor (cur );
416425 }
417426 }
418427
0 commit comments