About Programing/05. Android

Android에서 URI로 실제 파일 경로 가져오기

숙신 2011. 1. 4. 21:31

/**
 * URI로 부터 실제 파일 경로를 가져온다.
 * @param uriPath URI : URI 경로
 * @return String : 실제 파일 경로
 */
public String getRealImagePath (Uri uriPath)
{
	String []proj = {MediaStore.Images.Media.DATA};
	Cursor cursor = managedQuery (uriPath, proj, null, null, null);
	int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

	cursor.moveToFirst();

	String path = cursor.getString(index);
	path = path.substring(5);

	return path;
}