What is the suggested approach to allow user to export data on Android?

Viewed 39

I am creating an app and I need to add the possibility to export the data stored in the app.
Is there any best practice to follow?

At the moment I create a file in Context.cacheDir and notify DownloadManager about it.
The file cannot be opened in the end, but I am wondering if there is a best practice to follow for this kind of operations.

1 Answers

Personally, I would use ACTION_CREATE_DOCUMENT / ActivityResultContracts.CreateDocument for single-file exports. This will let the user decide where on the user's device (or in the user's cloud storage) you should export the user's data.

If your export involves multiple files, use ACTION_OPEN_DOCUMENT_TREE / ActivityResultContracts.OpenDocumentTree and create a sub-tree in which to place that content.

Related