This is the code that I use to select the image from the SD card.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),JobActivity.SELECT_PHOTO);
, .
onActivityResult .
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
if (resultCode == RESULT_OK) {
if (requestCode == JobActivity.SELECT_PHOTO) {
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
getBitmap(selectedImagePath, 0);
}
}
} catch (Exception e) {
Log.e("Error", "Unable to set thumbnail", e);
}
}
get Path
public String getPath(Uri uri) {
Cursor cursor = null;
int column_index = 0;
try {
String[] projection = { MediaStore.Images.Media.DATA };
cursor = managedQuery(uri, projection, null, null, null);
column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
} catch (Exception e) {
Log.d("Error", "Exception Occured", e);
}
return cursor.getString(column_index);
}
,
public Bitmap getBitmap(String path, int size) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = size;
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
return bitmap;
}
. , .
, , , .
/ Gallery Google