Created
October 10, 2013 18:29
-
-
Save sakurabird/6923154 to your computer and use it in GitHub Desktop.
android ギャラリーを呼び出し、選択したイメージのファイルパスを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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