在Android ICS中从内存中读取图像不起作用

时间:2012-06-11 13:53:33

标签: android android-4.0-ice-cream-sandwich

我有一个程序从图库中检索图像。这是我的代码:

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

以上代码在模拟器以及 Galaxy S 中使用 Android 2.2或2.3 时效果很好。但现在当我在 Galaxy Nexus 中运行它时,它无法从内存中读取图像。

唯一的区别是Galaxy Nexus在 Android 4.0 中运行,并且不支持 SDCard ,而是内部存储空间为13 GB。

所以我的问题是我应该在上面的代码中进行哪些更改,以便它可以在Nexus上运行。

我认为由于Nexus不支持外部存储,因此可以通过将URI从MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI更改为MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI来解决。这对我有用还是我必须做别的事。请指导我。

1 个答案:

答案 0 :(得分:1)

  

唯一的区别是Galaxy Nexus在Android 4.0中运行并且是   不支持SDCard,而是内部存储空间为13 GB。

你正试图从外部存储中读取:)

更改

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

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