본문 바로가기

잡동사니/Android

안드로이드 이미지의 절대 경로 가져오기

$ 이미지의 절대 경로를 구해주는 메서드

 

 

private String getRealPathFromURI(Uri contentURI) {

     

    String result;

    Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);

     

    if (cursor == null) { // Source is Dropbox or other similar local file path

        result = contentURI.getPath();

     

    } else {

        cursor.moveToFirst();

        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);

        result = cursor.getString(idx);

        cursor.close();

    }

     

    return result;

}

 

 


출처: https://dd00oo.tistory.com/entry/안드로이드-갤러리의-실제경로-가져오기 [순수의공간]