Reference

DocumentsProvider

DocumentsProvider is the Android base class an app subclasses to expose a tree of documents (files and folders) to other apps through the Storage Access Framework, surfacing them in the system file picker as a browsable source.

Android developmentAndroid

DocumentsProvider

Also known as: documents provider android, SAF provider, android documentsprovider

DocumentsProvider is the Android base class an app subclasses to expose a tree of documents (files and folders) to other apps through the Storage Access Framework, surfacing them in the system file picker as a browsable source.

  • Subclass of ContentProvider; declared in the manifest with the android.provider.action.DOCUMENTS_PROVIDER intent filter.
  • Powers the entries shown in the system file picker (Storage Access Framework).
  • Key methods: queryRoots, queryChildDocuments, queryDocument, and openDocument.

What DocumentsProvider does

A DocumentsProvider is a specialized ContentProvider that publishes a hierarchy of documents under custom URIs so other apps can browse, open, and (optionally) create or delete them through the Storage Access Framework (SAF). Cloud and storage apps (Google Drive, Dropbox, on-device file managers) register one so their content appears alongside local storage in the system document picker.

Subclasses implement core methods such as queryRoots() (the entry points shown in the picker), queryChildDocuments() (listing a folder), queryDocument() (metadata for one item), and openDocument() (returning a ParcelFileDescriptor for the bytes). Each document is identified by a provider-defined document ID, and the framework builds content URIs of the form `content://<authority>/document/<id>`.

How it ties into storage cleanup

When a cleaner app lets you pick a folder via ACTION_OPEN_DOCUMENT_TREE, the picker is populated by the registered DocumentsProviders. The app then walks that tree using SAF rather than raw file paths, which is the supported way to read user storage under scoped storage on Android 10 and later.

Implementing custom flags like FLAG_SUPPORTS_DELETE and FLAG_SUPPORTS_WRITE on a document controls whether external apps may remove or modify it. This is why a cleaner can enumerate large or duplicate files exposed by a provider but only delete them when the provider grants the delete capability and the user has granted tree access.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.