From c1f7b4e4227b91749e8f689cd9bed684284f3b47 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 21 Nov 2017 20:13:59 +0100 Subject: catch rare exception when transforming download uri to real path --- src/main/java/de/pixart/messenger/utils/FileUtils.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main/java/de/pixart/messenger') diff --git a/src/main/java/de/pixart/messenger/utils/FileUtils.java b/src/main/java/de/pixart/messenger/utils/FileUtils.java index 83d0e9fbc..e37f0d44a 100644 --- a/src/main/java/de/pixart/messenger/utils/FileUtils.java +++ b/src/main/java/de/pixart/messenger/utils/FileUtils.java @@ -19,6 +19,8 @@ import de.pixart.messenger.Config; 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 @@ -56,10 +58,12 @@ public class FileUtils { else if (isDownloadsDocument(uri)) { Log.d(Config.LOGTAG, "FileUtils is downloads document"); 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)) { -- cgit v1.2.3