Detailed changes
  
  
    
    @@ -422,7 +422,7 @@ public class ExportBackupService extends Worker {
         final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
         final ArrayList<Uri> uris = new ArrayList<>();
         for (final File file : files) {
-            uris.add(FileBackend.getUriForFile(context, file));
+            uris.add(FileBackend.getUriForFile(context, file, file.getName()));
         }
         intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
         intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  
  
  
    
    @@ -235,16 +235,17 @@ public class FileBackend {
 
     public static Uri getUriForUri(Context context, Uri uri) {
         if ("file".equals(uri.getScheme())) {
-            return getUriForFile(context, new File(uri.getPath()));
+            final var file = new File(uri.getPath());
+            return getUriForFile(context, file, file.getName());
         } else {
             return uri;
         }
     }
 
-    public static Uri getUriForFile(Context context, File file) {
+    public static Uri getUriForFile(Context context, File file, final String displayName) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Config.ONLY_INTERNAL_STORAGE || file.toString().startsWith(context.getCacheDir().toString())) {
             try {
-                return FileProvider.getUriForFile(context, getAuthority(context), file);
+                return FileProvider.getUriForFile(context, getAuthority(context), file, displayName);
             } catch (IllegalArgumentException e) {
                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                     throw new SecurityException(e);
@@ -1603,7 +1604,7 @@ public class FileBackend {
         }
         final File file = new File(directory, filename);
         file.getParentFile().mkdirs();
-        return getUriForFile(mXmppConnectionService, file);
+        return getUriForFile(mXmppConnectionService, file, filename);
     }
 
     public Avatar getPepAvatar(Uri image, int size, Bitmap.CompressFormat format) {
  
  
  
    
    @@ -1124,7 +1124,8 @@ public class NotificationService {
 
     private Uri fixRingtoneUri(Uri uri) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "file".equals(uri.getScheme())) {
-            return FileBackend.getUriForFile(mXmppConnectionService, new File(uri.getPath()));
+            final var file = new File(uri.getPath());
+            return FileBackend.getUriForFile(mXmppConnectionService, file, file.getName());
         } else {
             return uri;
         }
  
  
  
    
    @@ -2960,7 +2960,10 @@ public class ConversationFragment extends XmppFragment
         } else {
             final DownloadableFile file =
                     activity.xmppConnectionService.getFileBackend().getFile(message);
-            ViewUtil.view(activity, file);
+            final var fp = message.getFileParams();
+            final var name = fp == null ? null : fp.getName();
+            final var displayName = name == null ? file.getName() : name;
+            ViewUtil.view(activity, file, displayName);
         }
     }
 
@@ -3018,7 +3021,7 @@ public class ConversationFragment extends XmppFragment
 
         Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
         intent.addCategory(Intent.CATEGORY_OPENABLE);
-        intent.setType(MimeUtils.guessMimeTypeFromUri(activity, activity.xmppConnectionService.getFileBackend().getUriForFile(activity, file)));
+        intent.setType(MimeUtils.guessMimeTypeFromUri(activity, activity.xmppConnectionService.getFileBackend().getUriForFile(activity, file, file.getName())));
         intent.putExtra(Intent.EXTRA_TITLE, name);
 
         SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity);
  
  
  
    
    @@ -1715,7 +1715,10 @@ public class MessageAdapter extends ArrayAdapter<Message> {
         }
         final DownloadableFile file =
                 activity.xmppConnectionService.getFileBackend().getFile(message);
-        ViewUtil.view(activity, file);
+        final var fp = message.getFileParams();
+        final var name = fp == null ? null : fp.getName();
+        final var displayName = name == null ? file.getName() : name;
+        ViewUtil.view(activity, file, displayName);
     }
 
     private void showLocation(Message message) {
  
  
  
    
    @@ -65,8 +65,11 @@ public class ShareUtil {
 			shareIntent.putExtra(ConversationsActivity.EXTRA_AS_QUOTE, message.getStatus() == Message.STATUS_RECEIVED);
 		} else {
 			final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
+			final var fp = message.getFileParams();
+			final var name = fp == null ? null : fp.getName();
+			final var displayName = name == null ? file.getName() : name;
 			try {
-				shareIntent.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(activity, file));
+				shareIntent.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(activity, file, displayName));
 			} catch (SecurityException e) {
 				Toast.makeText(activity, activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
 				return;
  
  
  
    
    @@ -20,12 +20,13 @@ import eu.siacs.conversations.persistance.FileBackend;
 public class ViewUtil {
 
     public static void view(Context context, Attachment attachment) {
+        // TODO: accept displayName
         File file = new File(attachment.getUri().getPath());
         final String mime = attachment.getMime() == null ? "*/*" : attachment.getMime();
-        view(context, file, mime);
+        view(context, file, mime, file.getName());
     }
 
-    public static void view (Context context, DownloadableFile file) {
+    public static void view (Context context, DownloadableFile file, final String displayName) {
         if (!file.exists()) {
             Toast.makeText(context, R.string.file_deleted, Toast.LENGTH_SHORT).show();
             return;
@@ -34,15 +35,15 @@ public class ViewUtil {
         if (mime == null) {
             mime = "*/*";
         }
-        view(context, file, mime);
+        view(context, file, mime, displayName);
     }
 
-    private static void view(Context context, File file, String mime) {
+    private static void view(Context context, File file, String mime, final String displayName) {
         Log.d(Config.LOGTAG,"viewing "+file.getAbsolutePath()+" "+mime);
         final Intent openIntent = new Intent(Intent.ACTION_VIEW);
         final Uri uri;
         try {
-            uri = FileBackend.getUriForFile(context, file);
+            uri = FileBackend.getUriForFile(context, file, displayName);
         } catch (SecurityException e) {
             Log.d(Config.LOGTAG, "No permission to access " + file.getAbsolutePath(), e);
             Toast.makeText(context, context.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
@@ -50,6 +51,7 @@ public class ViewUtil {
         }
         openIntent.setDataAndType(uri, mime);
         openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+
         try {
             context.startActivity(openIntent);
         } catch (final ActivityNotFoundException e) {
  
  
  
    
    @@ -507,7 +507,7 @@ public class ExportBackupWorker extends Worker {
         final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
         final ArrayList<Uri> uris = new ArrayList<>();
         for (final File file : files) {
-            uris.add(FileBackend.getUriForFile(context, file));
+            uris.add(FileBackend.getUriForFile(context, file, file.getName()));
         }
         intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
         intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);