MediaStore
class MediaStore
kotlin.Any | |
↳ | android.provider.MediaStore |
The contract between the media provider and applications. Contains definitions for the supported URIs and columns.
The media provider provides an indexed collection of common media types, such as Audio
, Video
, and Images
, from any attached storage devices. Each collection is organized based on the primary MIME type of the underlying content; for example, image/*
content is indexed under Images
. The Files
collection provides a broad view across all collections, and does not filter by MIME type.
Summary
Nested classes | |
---|---|
Collection of all media with MIME type of |
|
abstract |
Download metadata columns. |
Collection of downloaded items. |
|
Media provider table containing an index of all files in the media storage, including non-media files. |
|
Collection of all media with MIME type of |
|
abstract |
Common media metadata columns. |
Photo picker metadata columns. |
|
Collection of all media with MIME type of |
Constants | |
---|---|
static String |
Permission that grants access to |
static String |
Permission that grants access to |
static String |
Standard Intent action that can be sent to have the camera application capture an image and return it. |
static String |
Intent action that can be sent to have the camera application capture an image and return it when the device is secured (e.g. with a pin, password, pattern, or face unlock). |
static String |
Activity Action: Allow the user to select images or videos provided by system and return it. |
static String |
Activity Action: Launch settings controlling images or videos selection with |
static String |
Standard action that can be sent to review the given media file. |
static String |
Standard action that can be sent to review the given media file when the device is secured (e.g. with a pin, password, pattern, or face unlock). |
static String |
Standard Intent action that can be sent to have the camera application capture a video and return it. |
static String |
The authority for the media provider |
static String |
Specify that the caller wants to receive the original media format without transcoding. |
static String |
When defined, the launched application is requested to set the given brightness value via |
static String |
Specify the maximum allowed recording duration in seconds. |
static String |
The name of the Intent-extra used to control the onCompletion behavior of a MovieView. |
static String |
The name of an Intent-extra used to control the UI of a ViewImage. |
static String |
The name of the Intent-extra used to define the album |
static String |
The name of the Intent-extra used to define the artist |
static String |
Specify the |
static String |
Specify the UID of the app that should be used to determine supported media capabilities while opening a media. |
static String |
The name of the Intent-extra used to define the search focus. |
static String |
The name of the Intent-extra used to define the genre. |
static String |
The name of the Intent-extra used to define the playlist. |
static String |
The name of the Intent-extra used to define the radio channel. |
static String |
The name of the Intent-extra used to define the song title |
static String |
The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video. |
static String |
The name of an optional intent-extra used to specify URIs for pre-selection in photo picker opened with |
static String |
The name of an optional intent-extra used to allow apps to specify the picker accent color. |
static String |
The name of an optional intent-extra used to allow ordered selection of items. |
static String |
The name of an optional intent-extra used to allow apps to specify the tab the picker should open with. |
static String |
The name of an optional intent-extra used to allow multiple selection of items and constrain maximum number of items that can be returned by |
static String |
The name of the Intent-extra used to control the orientation of a ViewImage or a MovieView. |
static String |
The name of an Intent-extra used to control the UI of a ViewImage. |
static String |
Specify the maximum allowed size. |
static String |
The name of the Intent-extra used to control the quality of a recorded video. |
static String |
An intent to perform a search for music media and automatically play content from the result when possible. |
static String |
Activity Action: Perform a search for media. |
static String |
Activity Action: Launch a music player. |
static String |
The name of the Intent action used to launch a camera in still image mode. |
static String |
The name of the Intent action used to launch a camera in still image mode for use when the device is secured (e.g. with a pin, password, pattern, or face unlock). |
static String |
An intent to perform a search for readable media and automatically play content from the result when possible. |
static String |
The name of the Intent action used to launch a camera in video mode. |
static String |
An intent to perform a search for video media and automatically play content from the result when possible. |
static Int |
Value indicating that the default matching behavior should be used, as defined by the key documentation. |
static Int |
Value indicating that operations should exclude items matching the criteria defined by this key. |
static Int |
Value indicating that operations should include items matching the criteria defined by this key. |
static Int |
Value indicating that operations should only operate on items explicitly matching the criteria defined by this key. |
static String |
Name of the file signaling the media scanner to ignore media in the containing directory and its subdirectories. |
static String |
Name of current volume being scanned by the media scanner. |
static String |
Name under which an activity handling |
static String |
Name under which an activity handling |
static Int |
One of the permitted values for |
static Int |
One of the permitted values for |
static String |
Flag that requests android. |
static String |
Flag that indicates if only the latest selection in the photoPicker for the calling app should be returned. |
static String |
Specify how |
static String |
Specify how |
static String |
Specify how |
static String |
Flag that requests android. |
static String |
Specify a |
static String |
The string that is used when a media attribute is not known. |
static String |
Synthetic volume name that provides a view of all content across the "external" storage of the device. |
static String |
Specific volume name that represents the primary external storage device at |
static String |
Synthetic volume name that provides a view of all content across the "internal" storage of the device. |
Public constructors | |
---|---|
Public methods | |
---|---|
static Boolean |
canManageMedia(context: Context) Returns whether the calling app is granted |
static PendingIntent |
createDeleteRequest(resolver: ContentResolver, uris: MutableCollection<Uri!>) Create a |
static PendingIntent |
createFavoriteRequest(resolver: ContentResolver, uris: MutableCollection<Uri!>, value: Boolean) Create a |
static PendingIntent |
createTrashRequest(resolver: ContentResolver, uris: MutableCollection<Uri!>, value: Boolean) Create a |
static PendingIntent |
createWriteRequest(resolver: ContentResolver, uris: MutableCollection<Uri!>) Create a |
static Uri? |
getDocumentUri(context: Context, mediaUri: Uri) Return a |
static MutableSet<String!> |
getExternalVolumeNames(context: Context) Return list of all specific volume names that make up |
static Long |
getGeneration(context: Context, volumeName: String) Return the latest generation value for the given volume. |
static Uri! |
Uri for querying the state of the media scanner. |
static Uri? |
getMediaUri(context: Context, documentUri: Uri) Return a |
static ParcelFileDescriptor |
getOriginalMediaFormatFileDescriptor(context: Context, fileDescriptor: ParcelFileDescriptor) Returns |
static Int |
The maximum limit for the number of items that can be selected using |
static MutableSet<String!> |
getRecentExternalVolumeNames(context: Context) Return list of all recent volume names that have been part of |
static Uri? |
getRedactedUri(resolver: ContentResolver, uri: Uri) Returns an EXIF redacted version of |
static MutableList<Uri!> |
getRedactedUri(resolver: ContentResolver, uris: MutableList<Uri!>) Returns a list of EXIF redacted version of |
static Boolean |
getRequireOriginal(uri: Uri) Return if the caller requires the original file contents when calling |
static String |
getVersion(context: Context) Return an opaque version string describing the |
static String |
getVersion(context: Context, volumeName: String) Return an opaque version string describing the |
static String |
getVolumeName(uri: Uri) Return the volume name that the given |
static Boolean |
isCurrentCloudMediaProviderAuthority(resolver: ContentResolver, authority: String) Returns |
static Boolean |
isCurrentSystemGallery(resolver: ContentResolver, uid: Int, packageName: String) Returns true if the given application is the current system gallery of the device. |
static Boolean |
isSupportedCloudMediaProviderAuthority(resolver: ContentResolver, authority: String) Returns |
static Unit |
notifyCloudMediaChangedEvent(resolver: ContentResolver, authority: String, currentMediaCollectionId: String) Notifies the OS about a cloud media event requiring a full or incremental media collection sync for the currently enabled cloud provider, |
static AssetFileDescriptor? |
openAssetFileDescriptor(resolver: ContentResolver, uri: Uri, mode: String, cancellationSignal: CancellationSignal?) Works exactly the same as |
static ParcelFileDescriptor? |
openFileDescriptor(resolver: ContentResolver, uri: Uri, mode: String, cancellationSignal: CancellationSignal?) Works exactly the same as |
static AssetFileDescriptor? |
openTypedAssetFileDescriptor(resolver: ContentResolver, uri: Uri, mimeType: String, opts: Bundle?, cancellationSignal: CancellationSignal?) Works exactly the same as |
static Uri |
setIncludePending(uri: Uri) Update the given |
static Uri |
setRequireOriginal(uri: Uri) Update the given |
Properties | |
---|---|
static Uri |
A content:// style uri to the authority for the media provider |
Constants
ACCESS_MEDIA_OWNER_PACKAGE_NAME_PERMISSION
static val ACCESS_MEDIA_OWNER_PACKAGE_NAME_PERMISSION: String
Permission that grants access to MediaColumns.OWNER_PACKAGE_NAME
of every accessible media file.
Value: "com.android.providers.media.permission.ACCESS_MEDIA_OWNER_PACKAGE_NAME"
ACCESS_OEM_METADATA_PERMISSION
static val ACCESS_OEM_METADATA_PERMISSION: String
Permission that grants access to MediaColumns.OEM_METADATA
of every accessible media file.
Value: "com.android.providers.media.permission.ACCESS_OEM_METADATA"
ACTION_IMAGE_CAPTURE
static val ACTION_IMAGE_CAPTURE: String
Standard Intent action that can be sent to have the camera application capture an image and return it.
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT. As of android.os.Build.VERSION_CODES#LOLLIPOP
, this uri can also be supplied through android.content.Intent#setClipData(ClipData)
. If using this approach, you still must supply the uri through the EXTRA_OUTPUT field for compatibility with old applications. If you don't set a ClipData, it will be copied there for you when calling Context.startActivity(Intent)
.
Regardless of whether or not EXTRA_OUTPUT is present, when an image is captured via this intent, android.hardware.Camera#ACTION_NEW_PICTURE
won't be broadcasted.
Note: if you app targets M
and above and declares as using the android.Manifest.permission#CAMERA
permission which is not granted, then attempting to use this action will result in a .
Value: "android.media.action.IMAGE_CAPTURE"
ACTION_IMAGE_CAPTURE_SECURE
static val ACTION_IMAGE_CAPTURE_SECURE: String
Intent action that can be sent to have the camera application capture an image and return it when the device is secured (e.g. with a pin, password, pattern, or face unlock). Applications responding to this intent must not expose any personal content like existing photos or videos on the device. The applications should be careful not to share any photo or video with other applications or Internet. The activity should use android.app.Activity#setShowWhenLocked
to display on top of the lock screen while secured. There is no activity stack when this flag is used, so launching more than one activity is strongly discouraged.
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT. As of android.os.Build.VERSION_CODES#LOLLIPOP
, this uri can also be supplied through android.content.Intent#setClipData(ClipData)
. If using this approach, you still must supply the uri through the EXTRA_OUTPUT field for compatibility with old applications. If you don't set a ClipData, it will be copied there for you when calling Context.startActivity(Intent)
.
Regardless of whether or not EXTRA_OUTPUT is present, when an image is captured via this intent, android.hardware.Camera#ACTION_NEW_PICTURE
won't be broadcasted.
Value: "android.media.action.IMAGE_CAPTURE_SECURE"
ACTION_PICK_IMAGES
static val ACTION_PICK_IMAGES: String
Activity Action: Allow the user to select images or videos provided by system and return it. This is different than Intent.ACTION_PICK
and Intent.ACTION_GET_CONTENT
in that
- the data for this action is provided by the system
- this action is only used for picking images and videos
- caller gets read access to user picked items even without storage permissions
Callers can optionally specify MIME type (such as image/*
or video/*
), resulting in a range of content selection that the caller is interested in. The optional MIME type can be requested with Intent.setType(String)
.
If the caller needs multiple returned items (or caller wants to allow multiple selection), then it can specify MediaStore.EXTRA_PICK_IMAGES_MAX
to indicate this.
When the caller requests multiple selection, the value of android.provider.MediaStore#EXTRA_PICK_IMAGES_MAX
must be a positive integer greater than 1 and less than or equal to MediaStore.getPickImagesMaxLimit
, otherwise Activity.RESULT_CANCELED
is returned. Use MediaStore.EXTRA_PICK_IMAGES_IN_ORDER
in multiple selection mode to allow the user to pick images in order.
Callers may use Intent.EXTRA_LOCAL_ONLY
to limit content selection to local data.
For system stability, it is preferred to open the URIs obtained from using this action by calling MediaStore.openFileDescriptor(ContentResolver, Uri, String, CancellationSignal)
, MediaStore.openAssetFileDescriptor(ContentResolver, Uri, String, CancellationSignal)
or MediaStore.openTypedAssetFileDescriptor(ContentResolver, Uri, String, Bundle, CancellationSignal)
instead of ContentResolver
open APIs.
Output: MediaStore content URI(s) of the item(s) that was picked. Unlike other MediaStore URIs, these are referred to as 'picker' URIs and expose a limited set of read-only operations. Specifically, picker URIs can only be opened for read and queried for columns in PickerMediaColumns
.
Before this API, apps could use Intent.ACTION_GET_CONTENT
. However, ACTION_PICK_IMAGES
is now the recommended option for images and videos, since it offers a better user experience.
Value: "android.provider.action.PICK_IMAGES"
ACTION_PICK_IMAGES_SETTINGS
static val ACTION_PICK_IMAGES_SETTINGS: String
Activity Action: Launch settings controlling images or videos selection with ACTION_PICK_IMAGES
. The settings page allows a user to change the enabled CloudMediaProvider
on the device and other media selection configurations.
Value: "android.provider.action.PICK_IMAGES_SETTINGS"
ACTION_REVIEW
static val ACTION_REVIEW: String
Standard action that can be sent to review the given media file.
The launched application is expected to provide a large-scale view of the given media file, while allowing the user to quickly access other recently captured media files.
Input: Intent.getData
is URI of the primary media item to initially display.
Value: "android.provider.action.REVIEW"
See Also
ACTION_REVIEW_SECURE
static val ACTION_REVIEW_SECURE: String
Standard action that can be sent to review the given media file when the device is secured (e.g. with a pin, password, pattern, or face unlock). The applications should be careful not to share any media with other applications or Internet. The activity should use Activity.setShowWhenLocked
to display on top of the lock screen while secured. There is no activity stack when this flag is used, so launching more than one activity is strongly discouraged.
The launched application is expected to provide a large-scale view of the given primary media file, while only allowing the user to quickly access other media from an explicit secondary list.
Input: Intent.getData
is URI of the primary media item to initially display. Intent.getClipData
is the limited list of secondary media items that the user is allowed to review. If Intent.getClipData
is undefined, then no other media access should be allowed.
Value: "android.provider.action.REVIEW_SECURE"
See Also
ACTION_VIDEO_CAPTURE
static val ACTION_VIDEO_CAPTURE: String
Standard Intent action that can be sent to have the camera application capture a video and return it.
The caller may pass in an extra EXTRA_VIDEO_QUALITY to control the video quality.
The caller may pass in an extra EXTRA_OUTPUT to control where the video is written.
- If EXTRA_OUTPUT is not present, the video will be written to the standard location for videos, and the Uri of that location will be returned in the data field of the Uri.
android.hardware.Camera#ACTION_NEW_VIDEO
will also be broadcasted when the video is recorded. - If EXTRA_OUTPUT is assigned a Uri value, no
android.hardware.Camera#ACTION_NEW_VIDEO
will be broadcasted. As ofandroid.os.Build.VERSION_CODES#LOLLIPOP
, this uri can also be supplied throughandroid.content.Intent#setClipData(ClipData)
. If using this approach, you still must supply the uri through the EXTRA_OUTPUT field for compatibility with old applications. If you don't set a ClipData, it will be copied there for you when callingContext.startActivity(Intent)
.
Note: if you app targets M
and above and declares as using the android.Manifest.permission#CAMERA
permission which is not granted, then atempting to use this action will result in a .
Value: "android.media.action.VIDEO_CAPTURE"
AUTHORITY
static val AUTHORITY: String
The authority for the media provider
Value: "media"
EXTRA_ACCEPT_ORIGINAL_MEDIA_FORMAT
static val EXTRA_ACCEPT_ORIGINAL_MEDIA_FORMAT: String
Specify that the caller wants to receive the original media format without transcoding. Caution: using this flag can cause app compatibility issues whenever Android adds support for new media formats. Clients should instead specify their supported media capabilities explicitly in their manifest or with the EXTRA_MEDIA_CAPABILITIES
open
flag. This option is useful for apps that don't attempt to parse the actual byte contents of media files, such as playback using MediaPlayer
or for off-device backup. Note that the android.Manifest.permission#ACCESS_MEDIA_LOCATION
permission will still be required to avoid sensitive metadata redaction, similar to setRequireOriginal(android.net.Uri)
. Note that this flag overrides any explicitly declared media_capabilities.xml
or ApplicationMediaCapabilities
extras specified in the same open
request.
This option can be added to the opts
Bundle
in various ContentResolver
open
methods.
Value: "android.provider.extra.ACCEPT_ORIGINAL_MEDIA_FORMAT"
See Also
EXTRA_BRIGHTNESS
static val EXTRA_BRIGHTNESS: String
When defined, the launched application is requested to set the given brightness value via android.view.WindowManager.LayoutParams#screenBrightness
to help ensure a smooth transition when launching ACTION_REVIEW
or ACTION_REVIEW_SECURE
intents.
Value: "android.provider.extra.BRIGHTNESS"
EXTRA_DURATION_LIMIT
static val EXTRA_DURATION_LIMIT: String
Specify the maximum allowed recording duration in seconds.
Value: "android.intent.extra.durationLimit"
EXTRA_FINISH_ON_COMPLETION
static val EXTRA_FINISH_ON_COMPLETION: String
The name of the Intent-extra used to control the onCompletion behavior of a MovieView. This is a boolean property that specifies whether or not to finish the MovieView activity when the movie completes playing. The default value is true, which means to automatically exit the movie player activity when the movie completes playing.
Value: "android.intent.extra.finishOnCompletion"
EXTRA_FULL_SCREEN
static val EXTRA_FULL_SCREEN: String
The name of an Intent-extra used to control the UI of a ViewImage. This is a boolean property that overrides the activity's default fullscreen state.
Value: "android.intent.extra.fullScreen"
EXTRA_MEDIA_ALBUM
static val EXTRA_MEDIA_ALBUM: String
The name of the Intent-extra used to define the album
Value: "android.intent.extra.album"
EXTRA_MEDIA_ARTIST
static val EXTRA_MEDIA_ARTIST: String
The name of the Intent-extra used to define the artist
Value: "android.intent.extra.artist"
EXTRA_MEDIA_CAPABILITIES
static val EXTRA_MEDIA_CAPABILITIES: String
Specify the ApplicationMediaCapabilities
that should be used while opening a media. If the capabilities specified matches the format of the original file, the app will receive the original file, otherwise, it will get transcoded to a default supported format. This flag takes higher precedence over the applications declared media_capabilities.xml
and is useful for apps that want to have more granular control over their supported media capabilities.
This option can be added to the opts
Bundle
in various ContentResolver
open
methods.
Value: "android.provider.extra.MEDIA_CAPABILITIES"
EXTRA_MEDIA_CAPABILITIES_UID
static val EXTRA_MEDIA_CAPABILITIES_UID: String
Specify the UID of the app that should be used to determine supported media capabilities while opening a media. If this specified UID is found to be capable of handling the original media file format, the app will receive the original file, otherwise, the file will get transcoded to a default format supported by the specified UID.
Value: "android.provider.extra.MEDIA_CAPABILITIES_UID"
EXTRA_MEDIA_FOCUS
static val EXTRA_MEDIA_FOCUS: String
The name of the Intent-extra used to define the search focus. The search focus indicates whether the search should be for things related to the artist, album or song that is identified by the other extras.
Value: "android.intent.extra.focus"
EXTRA_MEDIA_GENRE
static val EXTRA_MEDIA_GENRE: String
The name of the Intent-extra used to define the genre.
Value: "android.intent.extra.genre"
EXTRA_MEDIA_PLAYLIST
static valEXTRA_MEDIA_PLAYLIST: String
Deprecated: Android playlists are now deprecated. We will keep the current functionality for compatibility resons, but we will no longer take feature request. We do not advise adding new usages of Android Playlists. M3U files can be used as an alternative.
The name of the Intent-extra used to define the playlist.
Value: "android.intent.extra.playlist"
EXTRA_MEDIA_RADIO_CHANNEL
static val EXTRA_MEDIA_RADIO_CHANNEL: String
The name of the Intent-extra used to define the radio channel.
Value: "android.intent.extra.radio_channel"
EXTRA_MEDIA_TITLE
static val EXTRA_MEDIA_TITLE: String
The name of the Intent-extra used to define the song title
Value: "android.intent.extra.title"
EXTRA_OUTPUT
static val EXTRA_OUTPUT: String
The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video.
Value: "output"
EXTRA_PICKER_PRE_SELECTION_URIS
static val EXTRA_PICKER_PRE_SELECTION_URIS: String
The name of an optional intent-extra used to specify URIs for pre-selection in photo picker opened with MediaStore.ACTION_PICK_IMAGES
in multi-select mode.
Only MediaStore content URI(s) of the item(s) received as a result of MediaStore.ACTION_PICK_IMAGES
action are accepted. The value of this intent-extra should be an ArrayList of type URIs. Default value is null. Maximum number of URIs that can be accepted is limited by the value passed in MediaStore.EXTRA_PICK_IMAGES_MAX
as part of the MediaStore.ACTION_PICK_IMAGES
intent. In case the count of input URIs is greater than the limit then IllegalArgumentException
is thrown.
The provided list will be checked for permissions and authority. Any URI that is inaccessible, doesn't match the current authorities(local or cloud) or is invalid will be filtered out.
The items corresponding to the URIs will appear selected when the photo picker is opened. In the case of MediaStore.EXTRA_PICK_IMAGES_IN_ORDER
the chronological order of the input list will be used for ordered selection of the pre-selected items.
This is not a mechanism to revoke permissions for items, i.e. de-selection of a pre-selected item by the user will not result in revocation of the grant.
Value: "android.provider.extra.PICKER_PRE_SELECTION_URIS"
EXTRA_PICK_IMAGES_ACCENT_COLOR
static val EXTRA_PICK_IMAGES_ACCENT_COLOR: String
The name of an optional intent-extra used to allow apps to specify the picker accent color. The extra can only be specified in MediaStore.ACTION_PICK_IMAGES
. The accent color will be used for various primary elements in the PhotoPicker view. All other colors will be set based on android material guidelines.
The value of this intent extra should be a long color value. The alpha component of the given color is not taken into account while setting the accent color. We assume full color opacity. Only colors with luminance(can also be understood as brightness) greater than 0.05 and less than 0.9 are permitted. Luminance of a color is determined using: luminance = Color.luminance(color) where color is the input accent color to be set. Check Color docs for more details on color luminance and long color values. In case the luminance of the input color is unacceptable, picker colors will be set based on the colors of the device android theme. In case of an invalid input color value i.e. the input color cannot be parsed, IllegalArgumentException
is thrown.
Value: "android.provider.extra.PICK_IMAGES_ACCENT_COLOR"
EXTRA_PICK_IMAGES_IN_ORDER
static val EXTRA_PICK_IMAGES_IN_ORDER: String
The name of an optional intent-extra used to allow ordered selection of items. Set this extra to true to allow the user to see the order of their selected items. The result returned to the caller will be the same as the user selected order. This extra is only allowed via the MediaStore.ACTION_PICK_IMAGES
.
The value of this intent-extra should be a boolean. Default value is false.
Value: "android.provider.extra.PICK_IMAGES_IN_ORDER"
See Also
EXTRA_PICK_IMAGES_LAUNCH_TAB
static val EXTRA_PICK_IMAGES_LAUNCH_TAB: String
The name of an optional intent-extra used to allow apps to specify the tab the picker should open with. The extra can only be specified in MediaStore.ACTION_PICK_IMAGES
.
The value of this intent-extra must be one of: MediaStore.PICK_IMAGES_TAB_ALBUMS
for the albums tab and MediaStore.PICK_IMAGES_TAB_IMAGES
for the photos tab. The system will decide which tab to open by default and in most cases, it is MediaStore.PICK_IMAGES_TAB_IMAGES
i.e. the photos tab.
Value: "android.provider.extra.PICK_IMAGES_LAUNCH_TAB"
EXTRA_PICK_IMAGES_MAX
static val EXTRA_PICK_IMAGES_MAX: String
The name of an optional intent-extra used to allow multiple selection of items and constrain maximum number of items that can be returned by MediaStore.ACTION_PICK_IMAGES
, action may still return nothing (0 items) if the user chooses to cancel.
The value of this intent-extra should be a positive integer greater than 1 and less than or equal to MediaStore.getPickImagesMaxLimit
, otherwise Activity.RESULT_CANCELED
is returned.
Value: "android.provider.extra.PICK_IMAGES_MAX"
EXTRA_SCREEN_ORIENTATION
static val EXTRA_SCREEN_ORIENTATION: String
The name of the Intent-extra used to control the orientation of a ViewImage or a MovieView. This is an int property that overrides the activity's requestedOrientation.
Value: "android.intent.extra.screenOrientation"
EXTRA_SHOW_ACTION_ICONS
static val EXTRA_SHOW_ACTION_ICONS: String
The name of an Intent-extra used to control the UI of a ViewImage. This is a boolean property that specifies whether or not to show action icons.
Value: "android.intent.extra.showActionIcons"
EXTRA_SIZE_LIMIT
static val EXTRA_SIZE_LIMIT: String
Specify the maximum allowed size.
Value: "android.intent.extra.sizeLimit"
EXTRA_VIDEO_QUALITY
static val EXTRA_VIDEO_QUALITY: String
The name of the Intent-extra used to control the quality of a recorded video. This is an integer property. Currently value 0 means low quality, suitable for MMS messages, and value 1 means high quality. In the future other quality levels may be added.
Value: "android.intent.extra.videoQuality"
INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH
static val INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH: String
An intent to perform a search for music media and automatically play content from the result when possible. This can be fired, for example, by the result of a voice recognition command to listen to music.
This intent always includes the android.provider.MediaStore#EXTRA_MEDIA_FOCUS
and android.app.SearchManager#QUERY
extras. The android.provider.MediaStore#EXTRA_MEDIA_FOCUS
extra determines the search mode, and the value of the android.app.SearchManager#QUERY
extra depends on the search mode. For more information about the search modes for this intent, see Play music based on a search query in Common Intents.
This intent makes the most sense for apps that can support large-scale search of music, such as services connected to an online database of music which can be streamed and played on the device.
Value: "android.media.action.MEDIA_PLAY_FROM_SEARCH"
INTENT_ACTION_MEDIA_SEARCH
static val INTENT_ACTION_MEDIA_SEARCH: String
Activity Action: Perform a search for media. Contains at least the android.app.SearchManager#QUERY
extra. May also contain any combination of the following extras: EXTRA_MEDIA_ARTIST, EXTRA_MEDIA_ALBUM, EXTRA_MEDIA_TITLE, EXTRA_MEDIA_FOCUS
Value: "android.intent.action.MEDIA_SEARCH"
INTENT_ACTION_MUSIC_PLAYER
static valINTENT_ACTION_MUSIC_PLAYER: String
Deprecated: Use android.content.Intent#CATEGORY_APP_MUSIC
instead.
Activity Action: Launch a music player. The activity should be able to play, browse, or manipulate music files stored on the device.
Value: "android.intent.action.MUSIC_PLAYER"
INTENT_ACTION_STILL_IMAGE_CAMERA
static val INTENT_ACTION_STILL_IMAGE_CAMERA: String
The name of the Intent action used to launch a camera in still image mode.
Value: "android.media.action.STILL_IMAGE_CAMERA"
INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE
static val INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE: String
The name of the Intent action used to launch a camera in still image mode for use when the device is secured (e.g. with a pin, password, pattern, or face unlock). Applications responding to this intent must not expose any personal content like existing photos or videos on the device. The applications should be careful not to share any photo or video with other applications or internet. The activity should use android.app.Activity#setShowWhenLocked
to display on top of the lock screen while secured. There is no activity stack when this flag is used, so launching more than one activity is strongly discouraged.
Value: "android.media.action.STILL_IMAGE_CAMERA_SECURE"
INTENT_ACTION_TEXT_OPEN_FROM_SEARCH
static val INTENT_ACTION_TEXT_OPEN_FROM_SEARCH: String
An intent to perform a search for readable media and automatically play content from the result when possible. This can be fired, for example, by the result of a voice recognition command to read a book or magazine.
Contains the android.app.SearchManager#QUERY
extra, which is a string that can contain any type of unstructured text search, like the name of a book or magazine, an author a genre, a publisher, or any combination of these.
Because this intent includes an open-ended unstructured search string, it makes the most sense for apps that can support large-scale search of text media, such as services connected to an online database of books and/or magazines which can be read on the device.
Value: "android.media.action.TEXT_OPEN_FROM_SEARCH"
INTENT_ACTION_VIDEO_CAMERA
static val INTENT_ACTION_VIDEO_CAMERA: String
The name of the Intent action used to launch a camera in video mode.
Value: "android.media.action.VIDEO_CAMERA"
INTENT_ACTION_VIDEO_PLAY_FROM_SEARCH
static val INTENT_ACTION_VIDEO_PLAY_FROM_SEARCH: String
An intent to perform a search for video media and automatically play content from the result when possible. This can be fired, for example, by the result of a voice recognition command to play movies.
Contains the android.app.SearchManager#QUERY
extra, which is a string that can contain any type of unstructured video search, like the name of a movie, one or more actors, a genre, or any combination of these.
Because this intent includes an open-ended unstructured search string, it makes the most sense for apps that can support large-scale search of video, such as services connected to an online database of videos which can be streamed and played on the device.
Value: "android.media.action.VIDEO_PLAY_FROM_SEARCH"
MATCH_DEFAULT
static val MATCH_DEFAULT: Int
Value indicating that the default matching behavior should be used, as defined by the key documentation.
Value: 0
MATCH_EXCLUDE
static val MATCH_EXCLUDE: Int
Value indicating that operations should exclude items matching the criteria defined by this key.
Value: 2
MATCH_INCLUDE
static val MATCH_INCLUDE: Int
Value indicating that operations should include items matching the criteria defined by this key.
Note that items not matching the criteria may also be included depending on the default behavior documented by the key. If you want to operate exclusively on matching items, use MATCH_ONLY
.
Value: 1
MATCH_ONLY
static val MATCH_ONLY: Int
Value indicating that operations should only operate on items explicitly matching the criteria defined by this key.
Value: 3
MEDIA_IGNORE_FILENAME
static val MEDIA_IGNORE_FILENAME: String
Name of the file signaling the media scanner to ignore media in the containing directory and its subdirectories. Developers should use this to avoid application graphics showing up in the Gallery and likewise prevent application sounds and music from showing up in the Music app.
Value: ".nomedia"
MEDIA_SCANNER_VOLUME
static val MEDIA_SCANNER_VOLUME: String
Name of current volume being scanned by the media scanner.
Value: "volume"
META_DATA_REVIEW_GALLERY_PREWARM_SERVICE
static val META_DATA_REVIEW_GALLERY_PREWARM_SERVICE: String
Name under which an activity handling ACTION_REVIEW
or ACTION_REVIEW_SECURE
publishes the service name for its prewarm service.
This meta-data should reference the fully qualified class name of the prewarm service
The prewarm service can be bound before starting ACTION_REVIEW
or ACTION_REVIEW_SECURE
. An application implementing this prewarm service should do the absolute minimum amount of work to initialize its resources to efficiently handle an ACTION_REVIEW
or ACTION_REVIEW_SECURE
in the near future.
Value: "android.media.review_gallery_prewarm_service"
META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE
static val META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE: String
Name under which an activity handling INTENT_ACTION_STILL_IMAGE_CAMERA
or INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE
publishes the service name for its prewarm service.
This meta-data should reference the fully qualified class name of the prewarm service extending CameraPrewarmService
.
The prewarm service will get bound and receive a prewarm signal CameraPrewarmService#onPrewarm()
when a camera launch intent fire might be imminent. An application implementing a prewarm service should do the absolute minimum amount of work to initialize the camera in order to reduce startup time in likely case that shortly after a camera launch intent would be sent.
Value: "android.media.still_image_camera_preview_service"
PICK_IMAGES_TAB_ALBUMS
static val PICK_IMAGES_TAB_ALBUMS: Int
One of the permitted values for MediaStore.EXTRA_PICK_IMAGES_LAUNCH_TAB
to open the picker with albums tab.
Value: 0
PICK_IMAGES_TAB_IMAGES
static val PICK_IMAGES_TAB_IMAGES: Int
One of the permitted values for MediaStore.EXTRA_PICK_IMAGES_LAUNCH_TAB
to open the picker with photos tab.
Value: 1
QUERY_ARG_INCLUDE_RECENTLY_UNMOUNTED_VOLUMES
static val QUERY_ARG_INCLUDE_RECENTLY_UNMOUNTED_VOLUMES: String
Flag that requests android.content.ContentResolver#query to include content from recently unmounted volumes.
When the flag is set, android.content.ContentResolver#query will return content from all volumes(i.e., both mounted and recently unmounted volume whose content is still held by MediaProvider).
Note that the query result doesn't provide any hint for content from unmounted volume. It's strongly recommended to use default query to avoid accessing/operating on the content that are not available on the device.
The flag is useful for apps which manage their own database and query MediaStore in order to synchronize between MediaStore database and their own database.
Value: "android:query-arg-recently-unmounted-volumes"
QUERY_ARG_LATEST_SELECTION_ONLY
static val QUERY_ARG_LATEST_SELECTION_ONLY: String
Flag that indicates if only the latest selection in the photoPicker for the calling app should be returned. If set to true, all items that were granted to the calling app in the last selection are returned.
Selection in this scenario refers to when the user selects items in the permission prompt photo picker. The access for these items is granted to the calling app and these grants are persisted unless the user deselects a granted item explicitly.
The result excludes items owned by the calling app unless they are explicitly selected by the user.
Note: If there has been no user selections after the introduction of this feature then all the granted items will be returned.
This key can be placed in a Bundle
of extras and passed to android.content.ContentResolver#query.
Value: "android:query-arg-latest-selection-only"
QUERY_ARG_MATCH_FAVORITE
static val QUERY_ARG_MATCH_FAVORITE: String
Specify how MediaColumns.IS_FAVORITE
items should be filtered when performing a MediaStore
operation.
This key can be placed in a Bundle
of extras and passed to android.content.ContentResolver#query, android.content.ContentResolver#update, or android.content.ContentResolver#delete.
By default, favorite items are not filtered away from operations.
Value is either 0
or a combination of android.provider.MediaStore#MATCH_DEFAULT
, android.provider.MediaStore#MATCH_INCLUDE
, android.provider.MediaStore#MATCH_EXCLUDE
, and android.provider.MediaStore#MATCH_ONLY
Value: "android:query-arg-match-favorite"
QUERY_ARG_MATCH_PENDING
static val QUERY_ARG_MATCH_PENDING: String
Specify how MediaColumns.IS_PENDING
items should be filtered when performing a MediaStore
operation.
This key can be placed in a Bundle
of extras and passed to android.content.ContentResolver#query, android.content.ContentResolver#update, or android.content.ContentResolver#delete.
By default, pending items are filtered away from operations.
Value is either 0
or a combination of android.provider.MediaStore#MATCH_DEFAULT
, android.provider.MediaStore#MATCH_INCLUDE
, android.provider.MediaStore#MATCH_EXCLUDE
, and android.provider.MediaStore#MATCH_ONLY
Value: "android:query-arg-match-pending"
QUERY_ARG_MATCH_TRASHED
static val QUERY_ARG_MATCH_TRASHED: String
Specify how MediaColumns.IS_TRASHED
items should be filtered when performing a MediaStore
operation.
This key can be placed in a Bundle
of extras and passed to android.content.ContentResolver#query, android.content.ContentResolver#update, or android.content.ContentResolver#delete.
By default, trashed items are filtered away from operations.
Value is either 0
or a combination of android.provider.MediaStore#MATCH_DEFAULT
, android.provider.MediaStore#MATCH_INCLUDE
, android.provider.MediaStore#MATCH_EXCLUDE
, and android.provider.MediaStore#MATCH_ONLY
Value: "android:query-arg-match-trashed"
QUERY_ARG_MEDIA_STANDARD_SORT_ORDER
static val QUERY_ARG_MEDIA_STANDARD_SORT_ORDER: String
Flag that requests android.content.ContentResolver#query to sort the result in descending order based on MediaColumns.INFERRED_DATE
.
When this flag is used as an extra in a Bundle
passed to android.content.ContentResolver#query, all other sorting options such as android.content.ContentResolver#QUERY_ARG_SORT_COLUMNS
or android.content.ContentResolver#QUERY_ARG_SQL_SORT_ORDER
are disregarded.
Value: "android:query-arg-media-standard-sort-order"
QUERY_ARG_RELATED_URI
static val QUERY_ARG_RELATED_URI: String
Specify a Uri
that is "related" to the current operation being performed.
This is typically used to allow an operation that may normally be rejected, such as making a copy of a pre-existing image located under a MediaColumns.RELATIVE_PATH
where new images are not allowed.
It's strongly recommended that when making a copy of pre-existing content that you define the "original document ID" GUID as defined by the XMP Media Management standard.
This key can be placed in a Bundle
of extras and passed to android.content.ContentResolver#insert.
Value: "android:query-arg-related-uri"
UNKNOWN_STRING
static val UNKNOWN_STRING: String
The string that is used when a media attribute is not known. For example, if an audio file does not have any meta data, the artist and album columns will be set to this value.
Value: "<unknown>"
VOLUME_EXTERNAL
static val VOLUME_EXTERNAL: String
Synthetic volume name that provides a view of all content across the "external" storage of the device.
This synthetic volume provides a merged view of all media across all currently attached external storage devices.
Because this is a synthetic volume, you can't insert new content into this volume. Instead, you can insert content into a specific storage volume obtained from getExternalVolumeNames(android.content.Context)
.
Value: "external"
VOLUME_EXTERNAL_PRIMARY
static val VOLUME_EXTERNAL_PRIMARY: String
Specific volume name that represents the primary external storage device at Environment.getExternalStorageDirectory()
.
This volume may not always be available, such as when the user has ejected the device. You can find a list of all specific volume names using getExternalVolumeNames(android.content.Context)
.
Value: "external_primary"
VOLUME_INTERNAL
static val VOLUME_INTERNAL: String
Synthetic volume name that provides a view of all content across the "internal" storage of the device.
This synthetic volume provides a merged view of all media distributed with the device, such as built-in ringtones and wallpapers.
Because this is a synthetic volume, you can't insert new content into this volume.
Value: "internal"
Public constructors
Public methods
canManageMedia
static fun canManageMedia(context: Context): Boolean
Returns whether the calling app is granted android.Manifest.permission#MANAGE_MEDIA
or not.
Declaring the permission android.Manifest.permission#MANAGE_MEDIA
isn't enough to gain the access.
To request access, use android.provider.Settings#ACTION_REQUEST_MANAGE_MEDIA
.
Parameters | |
---|---|
context |
Context: the request context This value cannot be null . |
Return | |
---|---|
Boolean |
true, the calling app is granted the permission. Otherwise, false |
createDeleteRequest
static fun createDeleteRequest(
resolver: ContentResolver,
uris: MutableCollection<Uri!>
): PendingIntent
Create a PendingIntent
that will prompt the user to permanently delete the requested media items. When the user approves this request, android.content.ContentResolver#delete will be called on these items.
This call only generates the request for a prompt; to display the prompt, call android.app.Activity#startIntentSenderForResult with PendingIntent.getIntentSender()
. You can then determine if the user granted your request by testing for Activity.RESULT_OK
in Activity.onActivityResult
. The requested operation will have completely finished before this activity result is delivered.
The displayed prompt will reflect all the media items you're requesting, including those for which you already hold write access. If you want to determine if you already hold write access before requesting access, use Context.checkUriPermission(Uri, int, int, int)
with Intent.FLAG_GRANT_WRITE_URI_PERMISSION
.
Parameters | |
---|---|
resolver |
ContentResolver: Used to connect with MediaStore.AUTHORITY . Typically this value is Context.getContentResolver() , but if you need more explicit lifecycle controls, you can obtain a ContentProviderClient and wrap it using ContentResolver.wrap(ContentProviderClient) . This value cannot be null . |
uris |
MutableCollection<Uri!>: The set of media items to include in this request. Each item must be hosted by MediaStore.AUTHORITY and must reference a specific media item by BaseColumns._ID . This value cannot be null . |
Return | |
---|---|
PendingIntent |
This value cannot be null . |
createFavoriteRequest
static fun createFavoriteRequest(
resolver: ContentResolver,
uris: MutableCollection<Uri!>,
value: Boolean
): PendingIntent
Create a PendingIntent
that will prompt the user to favorite the requested media items. When the user approves this request, MediaColumns.IS_FAVORITE
is set on these items.
This call only generates the request for a prompt; to display the prompt, call android.app.Activity#startIntentSenderForResult with PendingIntent.getIntentSender()
. You can then determine if the user granted your request by testing for Activity.RESULT_OK
in Activity.onActivityResult
. The requested operation will have completely finished before this activity result is delivered.
The displayed prompt will reflect all the media items you're requesting, including those for which you already hold write access. If you want to determine if you already hold write access before requesting access, use Context.checkUriPermission(Uri, int, int, int)
with Intent.FLAG_GRANT_WRITE_URI_PERMISSION
.
Parameters | |
---|---|
resolver |
ContentResolver: Used to connect with MediaStore.AUTHORITY . Typically this value is Context.getContentResolver() , but if you need more explicit lifecycle controls, you can obtain a ContentProviderClient and wrap it using ContentResolver.wrap(ContentProviderClient) . This value cannot be null . |
uris |
MutableCollection<Uri!>: The set of media items to include in this request. Each item must be hosted by MediaStore.AUTHORITY and must reference a specific media item by BaseColumns._ID . This value cannot be null . |
value |
Boolean: The MediaColumns.IS_FAVORITE value to apply. |
Return | |
---|---|
PendingIntent |
This value cannot be null . |
createTrashRequest
static fun createTrashRequest(
resolver: ContentResolver,
uris: MutableCollection<Uri!>,
value: Boolean
): PendingIntent
Create a PendingIntent
that will prompt the user to trash the requested media items. When the user approves this request, MediaColumns.IS_TRASHED
is set on these items.
This call only generates the request for a prompt; to display the prompt, call android.app.Activity#startIntentSenderForResult with PendingIntent.getIntentSender()
. You can then determine if the user granted your request by testing for Activity.RESULT_OK
in Activity.onActivityResult
. The requested operation will have completely finished before this activity result is delivered.
The displayed prompt will reflect all the media items you're requesting, including those for which you already hold write access. If you want to determine if you already hold write access before requesting access, use Context.checkUriPermission(Uri, int, int, int)
with Intent.FLAG_GRANT_WRITE_URI_PERMISSION
.
Parameters | |
---|---|
resolver |
ContentResolver: Used to connect with MediaStore.AUTHORITY . Typically this value is Context.getContentResolver() , but if you need more explicit lifecycle controls, you can obtain a ContentProviderClient and wrap it using ContentResolver.wrap(ContentProviderClient) . This value cannot be null . |
uris |
MutableCollection<Uri!>: The set of media items to include in this request. Each item must be hosted by MediaStore.AUTHORITY and must reference a specific media item by BaseColumns._ID . This value cannot be null . |
value |
Boolean: The MediaColumns.IS_TRASHED value to apply. |
Return | |
---|---|
PendingIntent |
This value cannot be null . |
createWriteRequest
static fun createWriteRequest(
resolver: ContentResolver,
uris: MutableCollection<Uri!>
): PendingIntent
Create a PendingIntent
that will prompt the user to grant your app write access for the requested media items.
This call only generates the request for a prompt; to display the prompt, call android.app.Activity#startIntentSenderForResult with PendingIntent.getIntentSender()
. You can then determine if the user granted your request by testing for Activity.RESULT_OK
in Activity.onActivityResult
. The requested operation will have completely finished before this activity result is delivered.
Permissions granted through this mechanism are tied to the lifecycle of the Activity
that requests them. If you need to retain longer-term access for background actions, you can place items into a ClipData
or Intent
which can then be passed to Context.startService
or android.app.job.JobInfo.Builder#setClipData
. Be sure to include any relevant access modes you want to retain, such as Intent.FLAG_GRANT_WRITE_URI_PERMISSION
.
The displayed prompt will reflect all the media items you're requesting, including those for which you already hold write access. If you want to determine if you already hold write access before requesting access, use Context.checkUriPermission(Uri, int, int, int)
with Intent.FLAG_GRANT_WRITE_URI_PERMISSION
.
For security and performance reasons this method does not support Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
or Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
.
The write access granted through this request is general-purpose, and once obtained you can directly android.content.ContentResolver#update columns like MediaColumns.IS_FAVORITE
, MediaColumns.IS_TRASHED
, or android.content.ContentResolver#delete.
Parameters | |
---|---|
resolver |
ContentResolver: Used to connect with MediaStore.AUTHORITY . Typically this value is Context.getContentResolver() , but if you need more explicit lifecycle controls, you can obtain a ContentProviderClient and wrap it using ContentResolver.wrap(ContentProviderClient) . This value cannot be null . |
uris |
MutableCollection<Uri!>: The set of media items to include in this request. Each item must be hosted by MediaStore.AUTHORITY and must reference a specific media item by BaseColumns._ID . This value cannot be null . |
Return | |
---|---|
PendingIntent |
This value cannot be null . |
getDocumentUri
static fun getDocumentUri(
context: Context,
mediaUri: Uri
): Uri?
Return a DocumentsProvider
Uri that is an equivalent to the given MediaStore
Uri.
This allows apps with Storage Access Framework permissions to convert between MediaStore
and DocumentsProvider
Uris that refer to the same underlying item. Note that this method doesn't grant any new permissions; callers must already hold permissions obtained with Intent.ACTION_OPEN_DOCUMENT
or related APIs.
Parameters | |
---|---|
mediaUri |
Uri: The MediaStore Uri to convert. This value cannot be null . |
context |
Context: This value cannot be null . |
Return | |
---|---|
Uri? |
An equivalent DocumentsProvider Uri. Returns null if no equivalent was found. |
See Also
getExternalVolumeNames
static fun getExternalVolumeNames(context: Context): MutableSet<String!>
Return list of all specific volume names that make up VOLUME_EXTERNAL
. This includes a unique volume name for each shared storage device that is currently attached, which typically includes MediaStore.VOLUME_EXTERNAL_PRIMARY
.
Each specific volume name can be passed to APIs like MediaStore.Images.Media.getContentUri(String)
to interact with media on that storage device.
Parameters | |
---|---|
context |
Context: This value cannot be null . |
Return | |
---|---|
MutableSet<String!> |
This value cannot be null . |
getGeneration
static fun getGeneration(
context: Context,
volumeName: String
): Long
Return the latest generation value for the given volume.
Generation numbers are useful for apps that are attempting to quickly identify exactly which media items have been added or changed since a previous point in time. Generation numbers are monotonically increasing over time, and can be safely arithmetically compared.
Detecting media changes using generation numbers is more robust than using MediaColumns.DATE_ADDED
or MediaColumns.DATE_MODIFIED
, since those values may change in unexpected ways when apps use File.setLastModified(long)
or when the system clock is set incorrectly.
Note that before comparing these detailed generation values, you should first confirm that the overall version hasn't changed by checking MediaStore.getVersion(Context, String)
, since that indicates when a more radical change has occurred. If the overall version changes, you should assume that generation numbers have been reset and perform a full synchronization pass.
Parameters | |
---|---|
volumeName |
String: specific volume to obtain an generation value for. Must be one of the values returned from getExternalVolumeNames(android.content.Context) . This value cannot be null . |
context |
Context: This value cannot be null . |
getMediaScannerUri
static fun getMediaScannerUri(): Uri!
Uri for querying the state of the media scanner.
getMediaUri
static fun getMediaUri(
context: Context,
documentUri: Uri
): Uri?
Return a MediaStore
Uri that is an equivalent to the given DocumentsProvider
Uri. This only supports ExternalStorageProvider
and MediaDocumentsProvider
Uris.
This allows apps with Storage Access Framework permissions to convert between MediaStore
and DocumentsProvider
Uris that refer to the same underlying item. Note that this method doesn't grant any new permissions, but it grants the same access to the Media Store Uri as the caller has to the given DocumentsProvider Uri; callers must already hold permissions for documentUri obtained with Intent.ACTION_OPEN_DOCUMENT
or related APIs.
Parameters | |
---|---|
documentUri |
Uri: The DocumentsProvider Uri to convert. This value cannot be null . |
context |
Context: This value cannot be null . |
Return | |
---|---|
Uri? |
An equivalent MediaStore Uri. Returns null if no equivalent was found. |
See Also
getOriginalMediaFormatFileDescriptor
static fun getOriginalMediaFormatFileDescriptor(
context: Context,
fileDescriptor: ParcelFileDescriptor
): ParcelFileDescriptor
Returns ParcelFileDescriptor
representing the original media file format for fileDescriptor
.
Media files may get transcoded based on an application's media capabilities requirements. However, in various cases, when the application needs access to the original media file, or doesn't attempt to parse the actual byte contents of media files, such as playback using MediaPlayer
or for off-device backup, this method can be useful.
This method is applicable only for media files managed by MediaStore
.
The method returns the original file descriptor with the same permission that the caller has for the input file descriptor.
Parameters | |
---|---|
context |
Context: This value cannot be null . |
fileDescriptor |
ParcelFileDescriptor: This value cannot be null . |
Return | |
---|---|
ParcelFileDescriptor |
This value cannot be null . |
Exceptions | |
---|---|
java.io.IOException |
if the given ParcelFileDescriptor could not be converted |
getPickImagesMaxLimit
static fun getPickImagesMaxLimit(): Int
The maximum limit for the number of items that can be selected using MediaStore.ACTION_PICK_IMAGES
when launched in multiple selection mode. This can be used as a constant value for MediaStore.EXTRA_PICK_IMAGES_MAX
.
getRecentExternalVolumeNames
static fun getRecentExternalVolumeNames(context: Context): MutableSet<String!>
Return list of all recent volume names that have been part of VOLUME_EXTERNAL
.
These volume names are not currently mounted, but they're likely to reappear in the future, so apps are encouraged to preserve any indexed metadata related to these volumes to optimize user experiences.
Each specific volume name can be passed to APIs like MediaStore.Images.Media.getContentUri(String)
to interact with media on that storage device.
Parameters | |
---|---|
context |
Context: This value cannot be null . |
Return | |
---|---|
MutableSet<String!> |
This value cannot be null . |
getRedactedUri
static fun getRedactedUri(
resolver: ContentResolver,
uri: Uri
): Uri?
Returns an EXIF redacted version of uri
i.e. a Uri
with metadata such as location, GPS datestamp etc. redacted from the EXIF headers.
A redacted Uri can be used to share a file with another application wherein exposing sensitive information in EXIF headers is not desirable. Note: 1. Redacted uris cannot be granted write access and can neither be used to perform any kind of write operations. 2. To get a redacted uri the caller must hold read permission to uri
.
Parameters | |
---|---|
resolver |
ContentResolver: The ContentResolver used to connect with MediaStore.AUTHORITY . Typically this value is gotten from Context.getContentResolver() This value cannot be null . |
uri |
Uri: the Uri Uri to convert This value cannot be null . |
Return | |
---|---|
Uri? |
redacted version of the uri . Returns null when the given Uri could not be found or is unsupported |
Exceptions | |
---|---|
java.lang.SecurityException |
if the caller doesn't have the read access to uri |
getRedactedUri
static fun getRedactedUri(
resolver: ContentResolver,
uris: MutableList<Uri!>
): MutableList<Uri!>
Returns a list of EXIF redacted version of uris
i.e. a Uri
with metadata such as location, GPS datestamp etc. redacted from the EXIF headers.
A redacted Uri can be used to share a file with another application wherein exposing sensitive information in EXIF headers is not desirable. Note: 1. Order of the returned uris follow the order of the uris
. 2. Redacted uris cannot be granted write access and can neither be used to perform any kind of write operations. 3. To get a redacted uri the caller must hold read permission to its corresponding uri.
Parameters | |
---|---|
resolver |
ContentResolver: The ContentResolver used to connect with MediaStore.AUTHORITY . Typically this value is gotten from Context.getContentResolver() This value cannot be null . |
uris |
MutableList<Uri!>: the list of Uri Uri to convert This value cannot be null . |
Return | |
---|---|
MutableList<Uri!> |
a list with redacted version of uris , in the same order. Returns null when the corresponding Uri could not be found or is unsupported |
Exceptions | |
---|---|
java.lang.SecurityException |
if the caller doesn't have the read access to all the elements in uris |
java.lang.IllegalArgumentException |
if all the uris in uris don't belong to same user id |
getRequireOriginal
static fun getRequireOriginal(uri: Uri): Boolean
Return if the caller requires the original file contents when calling ContentResolver.openFileDescriptor(Uri, String)
.
Parameters | |
---|---|
uri |
Uri: This value cannot be null . |
getVersion
static fun getVersion(context: Context): String
Return an opaque version string describing the MediaStore
state.
Applications that import data from MediaStore
into their own caches can use this to detect that MediaStore
has undergone substantial changes, and that data should be rescanned.
No other assumptions should be made about the meaning of the version.
This method returns the version for MediaStore.VOLUME_EXTERNAL_PRIMARY
; to obtain a version for a different volume, use getVersion(android.content.Context,java.lang.String)
.
Parameters | |
---|---|
context |
Context: This value cannot be null . |
Return | |
---|---|
String |
This value cannot be null . |
getVersion
static fun getVersion(
context: Context,
volumeName: String
): String
Return an opaque version string describing the MediaStore
state.
Applications that import data from MediaStore
into their own caches can use this to detect that MediaStore
has undergone substantial changes, and that data should be rescanned.
No other assumptions should be made about the meaning of the version.
Parameters | |
---|---|
volumeName |
String: specific volume to obtain an opaque version string for. Must be one of the values returned from getExternalVolumeNames(android.content.Context) . This value cannot be null . |
context |
Context: This value cannot be null . |
Return | |
---|---|
String |
This value cannot be null . |
getVolumeName
static fun getVolumeName(uri: Uri): String
Return the volume name that the given Uri
references.
Parameters | |
---|---|
uri |
Uri: This value cannot be null . |
Return | |
---|---|
String |
This value cannot be null . |
isCurrentCloudMediaProviderAuthority
static fun isCurrentCloudMediaProviderAuthority(
resolver: ContentResolver,
authority: String
): Boolean
Returns true
if and only if the caller with authority
is the currently enabled CloudMediaProvider
. More specifically, false
is also returned if the calling uid doesn't match the uid of the authority
.
Parameters | |
---|---|
resolver |
ContentResolver: This value cannot be null . |
authority |
String: This value cannot be null . |
isCurrentSystemGallery
static fun isCurrentSystemGallery(
resolver: ContentResolver,
uid: Int,
packageName: String
): Boolean
Returns true if the given application is the current system gallery of the device.
The system gallery is one app chosen by the OEM that has read & write access to all photos and videos on the device and control over folders in media collections.
Parameters | |
---|---|
resolver |
ContentResolver: The ContentResolver used to connect with MediaStore.AUTHORITY . Typically this value is Context.getContentResolver() . This value cannot be null . |
uid |
Int: The uid to be checked if it is the current system gallery. |
packageName |
String: The package name to be checked if it is the current system gallery. This value cannot be null . |
isSupportedCloudMediaProviderAuthority
static fun isSupportedCloudMediaProviderAuthority(
resolver: ContentResolver,
authority: String
): Boolean
Returns true
if and only if the caller with authority
is a supported CloudMediaProvider
. More specifically, false
is also returned if the calling uid doesn't match the uid of the authority
.
Parameters | |
---|---|
resolver |
ContentResolver: This value cannot be null . |
authority |
String: This value cannot be null . |
notifyCloudMediaChangedEvent
static fun notifyCloudMediaChangedEvent(
resolver: ContentResolver,
authority: String,
currentMediaCollectionId: String
): Unit
Notifies the OS about a cloud media event requiring a full or incremental media collection sync for the currently enabled cloud provider, authority
. The OS will schedule the sync in the background and will attempt to batch frequent notifications into a single sync event. If the caller is not the currently enabled cloud provider as returned by isCurrentCloudMediaProviderAuthority(android.content.ContentResolver,java.lang.String)
, the request will be unsuccessful.
Parameters | |
---|---|
resolver |
ContentResolver: This value cannot be null . |
authority |
String: This value cannot be null . |
currentMediaCollectionId |
String: This value cannot be null . |
Exceptions | |
---|---|
java.lang.SecurityException |
if the request was unsuccessful. |
openAssetFileDescriptor
static fun openAssetFileDescriptor(
resolver: ContentResolver,
uri: Uri,
mode: String,
cancellationSignal: CancellationSignal?
): AssetFileDescriptor?
Works exactly the same as ContentResolver.openAssetFileDescriptor(Uri, String, CancellationSignal)
, but only works for Uri
whose scheme is ContentResolver.SCHEME_CONTENT
and its authority is MediaStore.AUTHORITY
.
This API is preferred over ContentResolver.openAssetFileDescriptor(Uri, String, CancellationSignal)
when opening media Uri for ensuring system stability especially when opening URIs returned as a result of using MediaStore.ACTION_PICK_IMAGES
Parameters | |
---|---|
resolver |
ContentResolver: The ContentResolver used to connect with MediaStore.AUTHORITY . Typically this value is gotten from Context.getContentResolver() This value cannot be null . |
uri |
Uri: The desired URI to open. This value cannot be null . |
mode |
String: The string representation of the file mode. Can be "r", "w", "wt", "wa", "rw" or "rwt". Please note the exact implementation of these may differ for each Provider implementation - for example, "w" may or may not truncate. This value cannot be null . |
cancellationSignal |
CancellationSignal?: This value may be null . |
Return | |
---|---|
AssetFileDescriptor? |
a new ParcelFileDescriptor pointing to the file or null if the provider recently crashed. You own this descriptor and are responsible for closing it when done. |
Exceptions | |
---|---|
java.io.FileNotFoundException |
if no file exists under the URI. |
java.lang.IllegalArgumentException |
if The URI is not for MediaStore.AUTHORITY |
openFileDescriptor
static fun openFileDescriptor(
resolver: ContentResolver,
uri: Uri,
mode: String,
cancellationSignal: CancellationSignal?
): ParcelFileDescriptor?
Works exactly the same as ContentResolver.openFileDescriptor(Uri, String, CancellationSignal)
, but only works for Uri
whose scheme is ContentResolver.SCHEME_CONTENT
and its authority is MediaStore.AUTHORITY
.
This API is preferred over ContentResolver.openFileDescriptor(Uri, String, CancellationSignal)
when opening media Uri for ensuring system stability especially when opening URIs returned as a result of using MediaStore.ACTION_PICK_IMAGES
Parameters | |
---|---|
resolver |
ContentResolver: The ContentResolver used to connect with MediaStore.AUTHORITY . Typically this value is gotten from Context.getContentResolver() This value cannot be null . |
uri |
Uri: The desired URI to open. This value cannot be null . |
mode |
String: The string representation of the file mode. Can be "r", "w", "wt", "wa", "rw" or "rwt". Please note the exact implementation of these may differ for each Provider implementation - for example, "w" may or may not truncate. This value cannot be null . |
cancellationSignal |
CancellationSignal?: A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown. |
Return | |
---|---|
ParcelFileDescriptor? |
a new ParcelFileDescriptor pointing to the file or null if the provider recently crashed. You own this descriptor and are responsible for closing it when done. |
Exceptions | |
---|---|
java.io.FileNotFoundException |
if no file exists under the URI. |
java.lang.IllegalArgumentException |
if The URI is not for MediaStore.AUTHORITY |
openTypedAssetFileDescriptor
static fun openTypedAssetFileDescriptor(
resolver: ContentResolver,
uri: Uri,
mimeType: String,
opts: Bundle?,
cancellationSignal: CancellationSignal?
): AssetFileDescriptor?
Works exactly the same as ContentResolver.openTypedAssetFileDescriptor(Uri, String, Bundle, CancellationSignal)
, but only works for Uri
whose scheme is ContentResolver.SCHEME_CONTENT
and its authority is MediaStore.AUTHORITY
.
This API is preferred over ContentResolver.openTypedAssetFileDescriptor(Uri, String, Bundle, CancellationSignal)
when opening media Uri for ensuring system stability especially when opening URIs returned as a result of using MediaStore.ACTION_PICK_IMAGES
Parameters | |
---|---|
resolver |
ContentResolver: The ContentResolver used to connect with MediaStore.AUTHORITY . Typically this value is gotten from Context.getContentResolver() This value cannot be null . |
uri |
Uri: The desired URI to open. This value cannot be null . |
mimeType |
String: The desired MIME type of the returned data. This can be a pattern such as */*, which will allow the content provider to select a type, though there is no way for you to determine what type it is returning. This value cannot be null . |
opts |
Bundle?: Additional provider-dependent options. This value may be null . |
cancellationSignal |
CancellationSignal?: This value may be null . |
Return | |
---|---|
AssetFileDescriptor? |
a new ParcelFileDescriptor from which you can read the data stream from the provider or null if the provider recently crashed. Note that this may be a pipe, meaning you can't seek in it. The only seek you should do is if the AssetFileDescriptor contains an offset, to move to that offset before reading. You own this descriptor and are responsible for closing it when done. |
Exceptions | |
---|---|
java.io.FileNotFoundException |
if no data of the desired type exists under the URI. |
java.lang.IllegalArgumentException |
if The URI is not for MediaStore.AUTHORITY |
setIncludePending
static funsetIncludePending(uri: Uri): Uri
Deprecated: consider migrating to QUERY_ARG_MATCH_PENDING
which is more expressive.
Update the given Uri
to also include any pending media items from calls such as ContentResolver.query(Uri, String[], Bundle, CancellationSignal)
. By default no pending items are returned.
Parameters | |
---|---|
uri |
Uri: This value cannot be null . |
Return | |
---|---|
Uri |
This value cannot be null . |
setRequireOriginal
static fun setRequireOriginal(uri: Uri): Uri
Update the given Uri
to indicate that the caller requires the original file contents when calling ContentResolver.openFileDescriptor(Uri, String)
.
This can be useful when the caller wants to ensure they're backing up the exact bytes of the underlying media, without any Exif redaction being performed.
If the original file contents cannot be provided, a UnsupportedOperationException
will be thrown when the returned Uri
is used, such as when the caller doesn't hold android.Manifest.permission#ACCESS_MEDIA_LOCATION
.
Parameters | |
---|---|
uri |
Uri: This value cannot be null . |
Return | |
---|---|
Uri |
This value cannot be null . |
Properties
AUTHORITY_URI
static val AUTHORITY_URI: Uri
A content:// style uri to the authority for the media provider