Skip to content

Commit

Permalink
CB-14097: (android) Fix crash when selecting some files with getPictu…
Browse files Browse the repository at this point in the history
…re (#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
  • Loading branch information
bvmensvoort authored and jcesarmobile committed Jul 5, 2018
1 parent 6899c5e commit 5c23b65
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/android/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,21 @@ public static String getRealPathFromURI_API11_And_Above(final Context context, f
else if (isDownloadsDocument(uri)) {

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);
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);
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
}
// MediaProvider
else if (isMediaDocument(uri)) {
Expand Down

0 comments on commit 5c23b65

Please sign in to comment.