Skip to content

Commit 5c23b65

Browse files
bvmensvoortjcesarmobile
authored andcommitted
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
1 parent 6899c5e commit 5c23b65

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/android/FileHelper.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,21 @@ public static String getRealPathFromURI_API11_And_Above(final Context context, f
9797
else if (isDownloadsDocument(uri)) {
9898

9999
final String id = DocumentsContract.getDocumentId(uri);
100-
final Uri contentUri = ContentUris.withAppendedId(
101-
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
102-
103-
return getDataColumn(context, contentUri, null, null);
100+
if (id != null && id.length() > 0) {
101+
if (id.startsWith("raw:")) {
102+
return id.replaceFirst("raw:", "");
103+
}
104+
try {
105+
final Uri contentUri = ContentUris.withAppendedId(
106+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
107+
108+
return getDataColumn(context, contentUri, null, null);
109+
} catch (NumberFormatException e) {
110+
return null;
111+
}
112+
} else {
113+
return null;
114+
}
104115
}
105116
// MediaProvider
106117
else if (isMediaDocument(uri)) {

0 commit comments

Comments
 (0)