Reputation: 21
I am capturing image via my application and I successfully stored in sdcard folder which I had created for my application. Now I need to retrieve the stored image in list view. Saving the images in sqlite is not an efficient way. Can any one direct me in any other way on how to save and retrieve like using path.
Am capturing picture here:
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
And I have also created the directory in sd card to save my captured images via my application below:
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File (
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES),
IMAGE_DIRECTORY_NAME
);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
+ IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type ==MEDIA_TYPE_IMAGE) {
mediaFile = new File (mediaStorageDir.getPath()+ File.separator
+ "IMG_" + timeStamp + ".jpg");
} else {
return null;
}
// TODO Auto-generated method stub
return mediaFile;
}
Upvotes: 0
Views: 4041