目前正在开发一个从 SD 卡加载图像的应用程序。在模拟器中,以下工作正常并找到要显示的图像。但是,在 Galaxy S2 和 S3 上 - 从未显示任何图像。有任何想法吗?
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
{ MediaStore.Images.Thumbnails._ID },
null,
null,
MediaStore.Images.Media._ID
);
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
int size = cursor.getCount();
int imageId = 0;
for (int i = 0; i < size; i++) {
if(cursor.isClosed()) {
continue;
}
cursor.moveToPosition(i);
imageId = cursor.getInt(columnIndex);
uri = Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
Integer.toString(imageId)
);
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
if (bitmap != null) {
newBitmap = Bitmap.createScaledBitmap(bitmap, 70, 70,true);
bitmap.recycle();
if (newBitmap != null) {
publishProgress(newBitmap);
}
}
} catch (IOException e) {}
}
cursor.close();
return null;