1

My app can share internally stored files with the androidx.core.content.FileProvider. The intent and the chooser are created with the following snippet:

val shareIntent: Intent = Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(
        Intent.EXTRA_STREAM,
        FileProvider.getUriForFile(this, authority, file, displayName),
    )
    type = document.mimeType.mediaType
}
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_title)))

I explicitly pass the displayName to the FileProvider, but in the app chooser, I see the file's local name (see image).

Intent.createChooser

Is there a way to show the correct display name in the chooser?

Massimo
  • 3,436
  • 4
  • 40
  • 68
  • That `displayName` parameter controls what the `FileProvider` returns for `OpenableColumns.DISPLAY_NAME` from `query()`. That in turn powers things like `getName()` on `DocumentFile`. However, there is no requirement that any consumer of the `Uri` actually get the display name. Given your filename, I am guessing that you are aiming for uniqueness. But, perhaps that uniqueness can be in the form of a directory, where the actual filename is your desired display name. – CommonsWare Dec 20 '22 at 14:47
  • @CommonsWare so the only option to be sure that the consumer of the `Uri` uses the right filename is to have the file with the final name, right? So if I don't have the file with that name I have to rename it or copy it somewhere in order to have it with that name. – Massimo Dec 20 '22 at 15:14
  • 1
    That chooser (or "share sheet") can vary by manufacturer and OS version. You cannot and should not be making any assumptions about what it looks like. My point is that you may have better luck if the filename is the desired display name. – CommonsWare Dec 20 '22 at 15:24

0 Answers0