これがあなたが探しているものだと思います
if (Environment.getExternalStorageState().equals("mounted")) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(
Intent.createChooser(
intent,
"Select Picture:"),
requestCode);
}
コールバックを処理します
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
Bitmap photo = getPreview(selectedImagePath);
}
public String getPath(Uri uri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(uri, proj, null, null, null);
if(cursor.moveToFirst()){;
int column_index = cursor.getColumnIndexOrThrow(proj[0]);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}
public Bitmap getPreview(String fileName) {
File image = new File(fileName);
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getPath(), bounds);
if ((bounds.outWidth == -1) || (bounds.outHeight == -1)) {
return null;
}
int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
: bounds.outWidth;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = originalSize / 64;
return BitmapFactory.decodeFile(image.getPath(), opts);
}
それが役に立てば幸い