Hi I am developing an Android Gallery app where I am fetching images from built in gallery and displaying it.I am using the code as below
String[] projection = {MediaStore.Images.Thumbnails._ID};
Cursor cursor = getContentResolver().query(MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int size = cursor.getCount();
// If size is 0, there are no images on the SD Card.
if (size == 0)
{
Log.e("size 0","0");
}
The Problem is when I run this code on Phones having only internal storage (Galaxy Nexus) I am getting Log which says size as Zero even though there are images in built in gallery. How do I resolve this. Please Help.Thanks!
To get list of Gallery images you can try this
Try this on your button like "Browse"
and you cal also set selected image into your ImageView as
In first block of code i use
startActivityForResult(i, RESULT_LOAD_IMAGE);
this return result to called activity and we can get this result by second block of code, and set selected image in your ImageViewReplace
MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI
withMediaStore.Images.MEDIA.EXTERNAL_CONTENT_URI
EDIT: Get the list of thumbnails and get the image URI from the cursor