From e39aa10134dd07ae3837d4c9eb6ec31c4374b750 Mon Sep 17 00:00:00 2001 From: Miguel Ruivo Date: Wed, 15 Apr 2020 22:05:37 +0100 Subject: [PATCH] Adds try-catch clause while querying for the file name --- .../java/com/mr/flutter/plugin/filepicker/FileUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java b/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java index a03ad87..c7d2f33 100644 --- a/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java +++ b/android/src/main/java/com/mr/flutter/plugin/filepicker/FileUtils.java @@ -172,8 +172,9 @@ public class FileUtils { //if uri is content if (uri.getScheme() != null && uri.getScheme().equals("content")) { - final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); + Cursor cursor = null; try { + cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { //local filesystem int index = cursor.getColumnIndex("_data"); @@ -189,6 +190,8 @@ public class FileUtils { return null; } } + } catch (final Exception ex) { + Log.e(TAG, "Failed to decode file name: " + ex.toString()); } finally { if (cursor != null) { cursor.close();