Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sakurabird
Created October 10, 2013 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sakurabird/6923154 to your computer and use it in GitHub Desktop.
Save sakurabird/6923154 to your computer and use it in GitHub Desktop.
android ギャラリーを呼び出し、選択したイメージのファイルパスを取得する
public void onClick5(View view) {
// ギャラリー呼び出し
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, REQUEST_GALLERY);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// これはパスを取るためだけのコードです。
if (requestCode == REQUEST_GALLERY && resultCode == RESULT_OK) {
// ContentResolver経由でファイルパスを取得
ContentResolver cr = getContentResolver();
String[] columns = {
MediaStore.Images.Media.DATA
};
Cursor c = cr.query(data.getData(), columns, null, null, null);
int column_index = c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
c.moveToFirst();
String path = c.getString(column_index);
Log.v("test", "path=" + path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment