Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
MediaProvider module
Stay organized with collections
Save and categorize content based on your preferences.
The MediaProvider module optimizes indexed metadata (audio, video, and images
from SD cards and USB devices) and makes that data available to apps through the
MediaStore public
APIs.
To maintain user privacy, the MediaProvider module enforces the scoped storage
security
model
introduced in Android 10, which includes redacting sensitive location metadata.
This module is updatable, enabling Android to respond faster to security issues
(keeping sensitive user data protected) and add new media formats quicker
(providing consistency to both users and developers).
Changes in Android 10
Android 10 introduced several improvements related to identifying and extracting
data from media files, specifically:
Determining the file content type using the first part of a file’s MIME type.
For example, the OS knows that both image/png
and
image/x-newly-invented-format
are images, and can thus accurately describe
relevant permissions to the end user.
Determining the MIME type using only the file extension (and without using
content sniffing
to avoid security issues).
Determining the MIME type of an arbitrary file using a combination of
upstream Debian Linux and Android
mappings.
Returning relevant data from video/*
and audio/*
files (via
MediaMetadataRetriever
) and image/*
files (via ExifInterface
).
Changes in Android 11
In Android 11, the MediaProvider module builds on the
changes made in Android 10 with the following improvements:
Improvements to indexing. The MediaProvider module now indexes metadata by
reconciling available metadata against MediaStore public APIs. Changes
include:
New is_favorite
column and QUERY_ARG_MATCH_FAVORITE
argument to enable
gallery-style apps to quickly filter media based on this column.
Indexing color space metadata.
New 'is_trashed' column and QUERY_ARG_MATCH_TRASHED
argument to enable
gallery-style apps to filter based on this column.
New APIs that enable bulk-modification of multiple items with a single user
dialog prompt, including createDeleteRequest()
, createFavoriteRequest()
,
createTrashRequest()
, and createWriteRequest()
.
New GENERATION_ADDED
and GENERATION_MODIFIED
columns for use in quickly
and reliably detecting changes that have occurred since a previous
synchronization point.
New GROUP BY
public API for use with additional metadata columns not
mentioned above.
Improvement to ExifInterface
to extract metadata from PNG and WebP
containers.
Improvements to SystemUI
to write DateTimeOriginal
metadata in screen
captures.
In addition, you can now customize MediaProvider by adding new media formats,
marking which storage devices should be indexed, and even replacing the MTP
stack. For details, see Customization.
Module boundary
Android 11 migrates all code in
packages/providers/MediaProvider
to a new location, with the notable exception
of MTP-related logic. In addition,
frameworks/base/core/java/android/provider/MediaStore.java
is now inside the
module boundary at packages/providers/MediaProvider
.
The MediaProvider module is in APK-in-APEX format.
Dependencies
MediaProvider dependencies are related to customizations (that
is, if you customize MediaProvider, you must ensure your implementation meets
the dependency associated with your customization).
When using custom or nonstandard media file formats (for example, a format
generated by a vendor-specific Camera app), you must register each custom
format with MimeUtils
and the Media Extractor module to enable indexing by
MediaProvider.
To ensure MediaProvider indexes a custom set of storage devices (such SD card
slots and USB ports) used in a StorageManagerService
implementation, set the
VolumeInfo.MOUNT_FLAG_INDEXABLE
flag.
When using a custom (non-AOSP) MTP implementation, ensure the implementation
relies solely on public and system APIs to enable the implementation to
interact with MediaStore.
Customization
You can now add new media formats, influence which storage devices are indexed,
and replace the MTP stack.
Custom media formats. For each new custom media format, you must provide a
mapping from the unique file extension to a MIME type. We strongly encourage
you to follow the IANA registration
process.
You can't redefine an extension or MIME type that's already defined in AOSP.
For video/*
and audio/*
files, MediaProvider continues consulting
MediaMetadataRetriever
. Use the Android 10 Media Extractors to return
metadata for custom formats.
For image/*
files, MediaProvider continues standardizing on Exif
for
metadata. You can extend android.media.ExifInterface
to extract and return
Exif
metadata for any custom image formats.
Storage devices indexing flag. MediaProvider indexes all volumes returned
by StorageManager.getStorageVolumes()
where
StorageVolume.getMediaStoreVolumeName()
is non-null. You can customize the
list of volumes returned to influence what is indexed, but we advise against
including transient volumes (such as USB OTG drives).
MTP stack replacement. Android 11 places the MTP
stack entirely outside the module boundary and ensures that it works against
public APIs.
Testing
You can verify the functionality of MediaProvider using the following tests:
To verify the functionality of MediaStore public APIs, use tests in the
CtsProviderTestCases
package of the Android Compatibility Test Suite (CTS).
To verify the functionality of MediaProvider internals, use tests in
MediaProviderTests
.
To run both sets of tests together, use the following atest
command:
atest --test-mapping packages/providers/MediaProvider
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-29 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# MediaProvider module\n\nThe MediaProvider module optimizes indexed metadata (audio, video, and images\nfrom SD cards and USB devices) and makes that data available to apps through the\n[MediaStore public\nAPIs](https://developer.android.com/reference/android/provider/MediaStore).\nTo maintain user privacy, the MediaProvider module enforces the [scoped storage\nsecurity\nmodel](https://developer.android.com/training/data-storage/files/external-scoped)\nintroduced in Android 10, which includes redacting sensitive location metadata.\nThis module is updatable, enabling Android to respond faster to security issues\n(keeping sensitive user data protected) and add new media formats quicker\n(providing consistency to both users and developers).\n\nChanges in Android 10\n---------------------\n\nAndroid 10 introduced several improvements related to identifying and extracting\ndata from media files, specifically:\n\n- Determining the file content type using the first part of a file's MIME type.\n For example, the OS knows that both `image/png` and\n `image/x-newly-invented-format` are images, and can thus accurately describe\n relevant permissions to the end user.\n\n- Determining the MIME type using only the file extension (and without using\n [content sniffing](https://en.wikipedia.org/wiki/Content_sniffing)\n to avoid security issues).\n\n- Determining the MIME type of an arbitrary file using a combination of\n [upstream Debian Linux and Android\n mappings](https://android-review.googlesource.com/c/platform/libcore/+/735506).\n\n- Returning relevant data from `video/*` and `audio/*` files (via\n `MediaMetadataRetriever`) and `image/*` files (via `ExifInterface`).\n\nChanges in Android 11\n---------------------\n\nIn Android 11, the MediaProvider module builds on the\nchanges made in Android 10 with the following improvements:\n\n- Improvements to indexing. The MediaProvider module now indexes metadata by\n reconciling available metadata against MediaStore public APIs. Changes\n include:\n\n - New `is_favorite` column and `QUERY_ARG_MATCH_FAVORITE` argument to enable\n gallery-style apps to quickly filter media based on this column.\n\n - Indexing color space metadata.\n\n - New 'is_trashed' column and `QUERY_ARG_MATCH_TRASHED` argument to enable\n gallery-style apps to filter based on this column.\n\n - New APIs that enable bulk-modification of multiple items with a single user\n dialog prompt, including `createDeleteRequest()`, `createFavoriteRequest()`,\n `createTrashRequest()`, and `createWriteRequest()`.\n\n - New `GENERATION_ADDED` and `GENERATION_MODIFIED` columns for use in quickly\n and reliably detecting changes that have occurred since a previous\n synchronization point.\n\n - New `GROUP BY` public API for use with additional metadata columns not\n mentioned above.\n\n- Improvement to `ExifInterface` to extract metadata from PNG and WebP\n containers.\n\n- Improvements to `SystemUI` to write `DateTimeOriginal` metadata in screen\n captures.\n\nIn addition, you can now customize MediaProvider by adding new media formats,\nmarking which storage devices should be indexed, and even replacing the MTP\nstack. For details, see [Customization](#customization).\n\nModule boundary\n---------------\n\nAndroid 11 migrates all code in\n`packages/providers/MediaProvider` to a new location, with the notable exception\nof MTP-related logic. In addition,\n`frameworks/base/core/java/android/provider/MediaStore.java` is now *inside* the\nmodule boundary at `packages/providers/MediaProvider`.\n\nPackage format\n--------------\n\nThe MediaProvider module is in APK-in-APEX format.\n\nDependencies\n------------\n\nMediaProvider dependencies are related to [customizations](#customization) (that\nis, if you customize MediaProvider, you must ensure your implementation meets\nthe dependency associated with your customization).\n\n- When using custom or nonstandard media file formats (for example, a format\n generated by a vendor-specific Camera app), you must register each custom\n format with `MimeUtils` and the Media Extractor module to enable indexing by\n MediaProvider.\n\n- To ensure MediaProvider indexes a custom set of storage devices (such SD card\n slots and USB ports) used in a `StorageManagerService` implementation, set the\n `VolumeInfo.MOUNT_FLAG_INDEXABLE` flag.\n\n- When using a custom (non-AOSP) MTP implementation, ensure the implementation\n relies solely on public and system APIs to enable the implementation to\n interact with MediaStore.\n\nCustomization\n-------------\n\nYou can now add new media formats, influence which storage devices are indexed,\nand replace the MTP stack.\n\n- **Custom media formats.** For each new custom media format, you must provide a\n mapping from the unique file extension to a MIME type. We strongly encourage\n you to follow the [IANA registration\n process](https://www.iana.org/assignments/media-types/media-types.xhtml).\n\n - You can't redefine an extension or MIME type that's already defined in AOSP.\n\n - For `video/*` and `audio/*` files, MediaProvider continues consulting\n `MediaMetadataRetriever`. Use the Android 10 Media Extractors to return\n metadata for custom formats.\n\n - For `image/*` files, MediaProvider continues standardizing on `Exif` for\n metadata. You can extend `android.media.ExifInterface` to extract and return\n `Exif` metadata for any custom image formats.\n\n- **Storage devices indexing flag.** MediaProvider indexes all volumes returned\n by `StorageManager.getStorageVolumes()` where\n `StorageVolume.getMediaStoreVolumeName()` is non-null. You can customize the\n list of volumes returned to influence what is indexed, but we advise against\n including transient volumes (such as USB OTG drives).\n\n- **MTP stack replacement.** Android 11 places the MTP\n stack entirely outside the module boundary and ensures that it works against\n public APIs.\n\nTesting\n-------\n\nYou can verify the functionality of MediaProvider using the following tests:\n\n- To verify the functionality of MediaStore public APIs, use tests in the\n `CtsProviderTestCases` package of the Android Compatibility Test Suite (CTS).\n\n- To verify the functionality of MediaProvider internals, use tests in\n `MediaProviderTests`.\n\nTo run both sets of tests together, use the following `atest` command: \n\n atest --test-mapping packages/providers/MediaProvider"]]