I'm trying to get the real path of a file stored in the Android file system (I'm testing on an Emulator with Android 8.1)
here is my code:
final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); For earlier versions of Android 8.0, the variable id contains a long value so the next line works as expected.
On Android 8 the variable id contains a path like this raw:/storage/emulated/0/Download/my_file.pdf, so the casting Long.valueOf(id)) throws a 'java.lang.NumberFormatException' Exception.
Any ideas? Thanks.
Had the same problem solved it by doing the following.
final String id = DocumentsContract.getDocumentId(uri); if (!TextUtils.isEmpty(id)) { if (id.startsWith("raw:")) { return id.replaceFirst("raw:", ""); } try { final Uri contentUri = ContentUris.withAppendedId( Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } catch (NumberFormatException e) { return null; } } Solution was found in a comment https://github.com/Yalantis/uCrop/issues/318
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