how can I get the actual file path on the SD card where a content:// uri is pointing for an image?
Uri uri = data. getData(); File file = new File(uri. getPath());//create path from uri final String[] split = file. getPath().
From what I know you can find the path of a file in the internal storage with java simply by using: String path = context. getFilesDir(). getAbsolutePath(); File file = new File(path + "/filename");
I've adapted the code which @hooked82 linked to:
protected String convertMediaUriToPath(Uri uri) {
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
return path;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With