From d6eb08e0eda72fb00aa1d22f986e460f284812ed Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 10 Nov 2017 20:18:09 +0100 Subject: [PATCH] catch rare exception when transforming download uri to real path --- .../java/eu/siacs/conversations/utils/FileUtils.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/FileUtils.java b/src/main/java/eu/siacs/conversations/utils/FileUtils.java index 6e75d41cd..20d605506 100644 --- a/src/main/java/eu/siacs/conversations/utils/FileUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/FileUtils.java @@ -14,6 +14,8 @@ import java.io.File; public class FileUtils { + private static final Uri PUBLIC_DOWNLOADS = Uri.parse("content://downloads/public_downloads"); + /** * Get a file path from a Uri. This will get the the path for Storage Access * Framework Documents, as well as the _data field for the MediaStore and @@ -49,10 +51,12 @@ public class FileUtils { 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); + try { + final Uri contentUri = ContentUris.withAppendedId(PUBLIC_DOWNLOADS, Long.valueOf(id)); + return getDataColumn(context, contentUri, null, null); + } catch (NumberFormatException e) { + return null; + } } // MediaProvider else if (isMediaDocument(uri)) {