Reading images from memory in Android ICS not working

I have a program which retrieves the images from the Gallery. Here is my code:

String[] id = {MediaStore.Images.Thumbnails._ID};
Cursor imageCursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, id, null, null, MediaStore.Images.Thumbnails.IMAGE_ID);
int image_col_index = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int count = imageCursor.getCount();
//in a loop the below code goes {
    ImageView i = new ImageView(mContext.getApplicationContext());
    imageCursor.moveToPosition(position);
    int id = imageCursor.getInt(image_col_index);
    i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+ id));
    i.setScaleType(ImageView.ScaleType.CENTER_CROP);
    i.setLayoutParams(new GridView.LayoutParams(70, 70));
    //here I am storing this image i to a list for further use
}//here loop ends

The above code works fine in Emulator as well as in Galaxy S with Android 2.2 or 2.3 . But now when I run it in Galaxy Nexus , it fails to read images from memory.

The only difference is Galaxy Nexus is running in Android 4.0 and is not supporting SDCard instead it has an internal storage of 13 GB.

So my question is what should I change in the above code so that it could run on Nexus.

I am thinking that as Nexus does not support external storage, so it could be solved by changing the URI from MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI to MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI . Will this work for me or I have to do something else. Please guide me.


The only difference is Galaxy Nexus is running in Android 4.0 and is not supporting SDCard instead it has an internal storage of 13 GB.

And you are trying to read from external storage :)

Change

i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+ id));

To

i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI, ""+ id));
链接地址: http://www.djcxy.com/p/67502.html

上一篇: Android内部存储错误

下一篇: 在Android ICS的内存中读取图像无法正常工作