Reputation: 4614
Hi I am picking any file in android using following intent :
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
I am getting Uri for picked file & also I am getting file path by calling uri.getPath()
method. After getting path I am creating file object using file = new File(new URI(filePath));
but I am getting IllegalArgumentException : URI is not absolute
. Why is so ? How do I get Absolute Path ? Is there any other alternative to pick any file using Intent & then Uri ?
In android debugger uri object shows like (It is from downloads): content://com.android.providers.downloads.documents/document/67
& uri.getPath()
gives me /document/67
Upvotes: 3
Views: 2011
Reputation: 8209
Returned Uri
may have scheme that differs from file://
, i.e. it is not always a URI to local file or to file available to all device apps. E.g. it may be content://
URI and its path has nothing in common with local filesystem path. Fair way to workaround it - test if scheme is file://
and if not - open InputStream
via context.getContentResolver().openInputStream(uri)
and then copy content to local temporary file.
Upvotes: 4