[Android] - Intent.ACTION_GET_CONTENT FileName 찾기
Android Java 2018. 3. 27. 17:06======= 호출 =======
Intent intent = new Intent();
intent.setType( "image/*" );
intent.setAction( Intent.ACTION_GET_CONTENT );
startActivityForResult( intent, 1 );
======= 응답 =======
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri tempUri = data.getData();
String result = "";
if( tempUri.getScheme().equals( "content" ) ) {
Cursor cursor = getContentResolver().query( tempUri, null, null, null, null );
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex( OpenableColumns.DISPLAY_NAME ) );
}
} finally {
cursor.close();
}
}
if( result == null ) {
result = tempUri.getPath();
int cut = result.lastIndexOf( "/" );
if( cut != -1 ) {
result = result.substring( cut + 1 );
}
}
Log.e( "TAG", "FileName : " + result );
}
'Android Java' 카테고리의 다른 글
[Android] - 해당 앱 ( 앱 정보 페이지 ) intent (0) | 2019.05.28 |
---|---|
[Android Java] - RecyclerView 리스트 멀티셀렉트 해제 ( RecyclerView Disable Multiple select, splitMotionEvents ) (0) | 2018.07.17 |
[Android] - NavigationView state_checked 배경색상 변경 (0) | 2017.12.14 |
[Android] - Bitmap from uri ( PS. ImageSize small or normal ) (0) | 2017.12.07 |
[Android] - WebView loadData 한글 깨짐 ( UTF-8 ) 인코딩 (0) | 2017.11.29 |