From d254d24d77044adc2897f7f678c0bc02fb900978 Mon Sep 17 00:00:00 2001 From: Fumiaki Yoshimatsu Date: Sun, 21 Feb 2021 14:21:20 -0500 Subject: [PATCH] Use the last part of the URI if the scheme is "file" to avoid returning null as the file's name. Fixes #8561 --- .../org/thoughtcrime/securesms/sharing/ShareRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/sharing/ShareRepository.java b/app/src/main/java/org/thoughtcrime/securesms/sharing/ShareRepository.java index 64d0015018..e634cefba7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/sharing/ShareRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/sharing/ShareRepository.java @@ -233,6 +233,10 @@ class ShareRepository { } private static @Nullable String getFileName(@NonNull Context context, @NonNull Uri uri) { + if (uri.getScheme().equalsIgnoreCase("file")) { + return uri.getLastPathSegment(); + } + try (Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) { if (cursor != null && cursor.moveToFirst() && cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) >= 0) { return cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));