Reputation: 6922
I use below code to get the bitmap of all sd card photo.
String[] projection = {MediaStore.Images.Media._ID,MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Media._ID);
int count = cursor.getCount();
int image_column_index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
path = new String[count];
bm = new Bitmap[count];
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int id = cursor.getInt(image_column_index);
path[i] //How to get path
bt[i] = MediaStore.Images.Thumbnails.getThumbnail(getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
}
I already get the thumbnail of all photo. But I want to get the absolute path. Where should I modify?
Upvotes: 2
Views: 21106
Reputation: 5177
Images.ImageColumns.DATA
is the path
How to use it:
int image_column_index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
int image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
//added ...
path[i] = cursor.getString(image_path_index);
Upvotes: 8
Reputation: 10083
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == yourRequestCode) {
currImageURI = data.getData();
}
}
}
// Convert the image URI to the direct file system path
public String getRealPathFromURI(Uri contentUri) {
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
In Latest OS managed query
is deprecated So use
yourActivity.getContentResolver().query
instead of it, Both uses the same arguments
Upvotes: 1