What is the easiest way to convert from an android.net.Uri object which holds a file: type to a java.io.File object in Android?
I tried the following but it doesn’t work:
File file = new File(Environment.getExternalStorageDirectory(), "read.me");
Uri uri = Uri.fromFile(file);
File auxFile = new File(uri.toString());
assertEquals(file.getAbsolutePath(), auxFile.getAbsolutePath());
What you want is…
… and not…
Notes
android.net.Uriobject which is nameduriand created exactly as in the question,uri.toString()returns aStringin the format"file:///mnt/sdcard/myPicture.jpg", whereasuri.getPath()returns aStringin the format"/mnt/sdcard/myPicture.jpg".