Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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