From 5c23b65af9b11fa3a17bd44513418113dea9b8ed Mon Sep 17 00:00:00 2001 From: bvmensvoort Date: Fri, 6 Jul 2018 00:16:25 +0200 Subject: [PATCH] CB-14097: (android) Fix crash when selecting some files with getPicture (#322) * CB-14097: (android) Fix crash when selecting some files with getPicture of urls with raw:// Handles both urls: content://com.android.providers.downloads.documents/document/1111 content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ffilename.pdf * Optimization: Remove TextUtils dependency, return null when no id could be extracted --- src/android/FileHelper.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/android/FileHelper.java b/src/android/FileHelper.java index ccc5e3e..edf1657 100644 --- a/src/android/FileHelper.java +++ b/src/android/FileHelper.java @@ -97,10 +97,21 @@ public class FileHelper { else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); - final Uri contentUri = ContentUris.withAppendedId( - Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + if (id != null && id.length() > 0) { + 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); + return getDataColumn(context, contentUri, null, null); + } catch (NumberFormatException e) { + return null; + } + } else { + return null; + } } // MediaProvider else if (isMediaDocument(uri)) {