tags:

views:

735

answers:

1

What's the easiest way to convert from a file: android.net.Uri to a File in Android?

Tried the following but it doesn't work:

 final File file = new File(Environment.getExternalStorageDirectory(), "read.me");
 Uri uri = Uri.fromFile(file);
 File auxFile = new File(uri.toString());
 assertEquals(file.getAbsolutePath(), auxFile.getAbsolutePath());
+4  A: 

EDIT: Sorry, I should have tested better before. This should work:

new File(new URI(androidURI.toString()));

URI is java.net.URI.

Matthew Flaschen
That doesn't work for me. See expanded question.
hgpc
It works. Tested with various cases and special characters. Thanks!
hgpc