user19576538
user19576538

Reputation:

How to get the file name using a returned URI

I'm letting users pick a file from their device using:

registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> ... }

I want to find out what is the name of the file they've picked. How can I retrieve the file name?

Upvotes: 1

Views: 451

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006734

You can get a display name via DocumentFile:

DocumentFile.fromSingleUri(uri).name

What the "display name" is will be up to the DocumentsProvider that the user is using. If the user is working with a filesystem-based provider, the display name probably is a filename.

Upvotes: 4

Related Questions