Interfaces (Others)

NOTE

The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { photoAccessHelper } from '@kit.MediaLibraryKit';

MediaChangeRequest11+

Media change request, which is the parent class of the asset change request and album change request.

NOTE

MediaChangeRequest takes effect only after applyChanges is called.

Attributes

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 23.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
comment23+ string Yes No Used to verify the MediaChangeRequest type.
If a class (such as MediaAssetChangeRequest or MediaAlbumChangeRequest) object can be accessed, it is an implementation class of MediaChangeRequest.

CreateOptions

Defines the options for creating an image or video asset.

The title must meet the following requirements:

  • It must not contain a file name extension.
  • The total length of the file name must be between 1 and 255 characters.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
title string No Yes Title of the image or video.
Atomic service API: This API can be used in atomic services since API version 11.
subtype12+ PhotoSubtype No Yes Subtype of the image or video file.
Atomic service API: This API can be used in atomic services since API version 12.

FetchOptions

Defines the retrieval options.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
fetchColumns Array<string> No No Names of the columns specified for query.
If this parameter is left blank for photos, photos are fetched by 'uri', 'media_type', 'subtype', and 'display_name' by default. An error will be thrown if get is used to obtain other attributes of this object.
Example: fetchColumns: ['uri', 'title'].
If this parameter is left blank for albums, albums are fetched by 'uri' and 'album_name' by default.
Atomic service API: This API can be used in atomic services since API version 20.
predicates dataSharePredicates.DataSharePredicates No No Predicates that specify the fetch criteria.
Atomic service API: This API can be used in atomic services since API version 20.

RequestOptions11+

Represents request options.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
deliveryMode DeliveryMode No No Delivery mode of the requested asset. The value can be FAST_MODE, HIGH_QUALITY_MODE, or BALANCE_MODE.
compatibleMode15+ CompatibleMode No Yes HDR video transcoding policy, which can be FAST_ORIGINAL_FORMAT_MODE (maintaining the original HDR format) or COMPATIBLE_FORMAT_MODE (converting HDR content to SDR format). The default value is FAST_ORIGINAL_FORMAT_MODE.
mediaAssetProgressHandler15+ MediaAssetProgressHandler No Yes Callback used to return the HDR-to-SDR conversion progress.

ChangeData

Defines the return value of the listener callback.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
type NotifyType No No Notification type.
uris Array<string> No No All URIs with the same NotifyType, which can be PhotoAsset or Album.
extraUris Array<string> No No URIs of the changed files in the album. The value may be undefined. Check whether the value is undefined before using it.

TextContextInfo12+

Represents the text information about the recommended images.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
text string No Yes Text based on which images are recommended. The text cannot exceed 250 characters. The default value is an empty string.

Example

import { BusinessError } from '@kit.BasicServicesKit';

async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
  try {
    let textInfo: photoAccessHelper.TextContextInfo = {
      text: 'Pandas at Shanghai Wild Zoo'
    }
    let recommendOptions: photoAccessHelper.RecommendationOptions = {
      textContextInfo: textInfo
    }
    let options: photoAccessHelper.PhotoSelectOptions = {
      MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE,
      maxSelectNumber: 1,
      recommendationOptions: recommendOptions
    }
    let photoPicker = new photoAccessHelper.PhotoViewPicker();
    photoPicker.select(options).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => {
      console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
    }).catch((err: BusinessError) => {
      console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`);
    });
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`);
  }
}

PhotoCreationConfig12+

Represents the configuration for saving a media asset (image or video) to the media library, including the file name.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
title string No Yes Title of the image or video. If this parameter is not passed, the system generates a title. The title must meet the following requirements:
- It must not contain a file name extension.
- The total length of the file name, which is in the format of title+file name extension, must be between 1 and 255 characters.
- It must not contain any invalid characters, which are:\ / : * ? " ' ` < > | { } [ ]
fileNameExtension string No No File name extension, for example, 'jpg'.
photoType PhotoType No No Type of the file to create, which can be IMAGE or VIDEO. See PhotoType.
subtype PhotoSubtype No Yes Image or video file subtype. The default value is DEFAULT. See PhotoSubtype.

CreationSetting23+

Represents the configuration for saving images or videos to the media library, including the file name, file type, and other related parameters.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 23.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
title string No Yes Title of the image or video.
If this parameter is not passed, the system generates a value. The parameter specifications are as follows:
- It must not contain a file name extension.
- It must not contain any invalid characters, which are:\ / : * ? " ' ` < > | { } [ ]
- The file name consists of the title and file name extension. The file name string length ranges from 1 to 255. Therefore, the title length cannot be too long.
fileNameExtension string No No File name extension, for example, 'jpg'.
photoType PhotoType No No PhotoType of the created media file, which can be IMAGE or VIDEO.

PhotoAssetChangeInfo20+

Describes the information about a media asset.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
uri string No No URI of the media asset.
mediaType PhotoType No No Type of the media asset (image or video).
albumUri string No No URI of the album that the media asset belongs to.

PhotoAssetChangeData20+

Describes the detailed change data of a media asset.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
assetBeforeChange PhotoAssetChangeInfo | null No No Data of the media asset before change. In the case of asset addition, assetBeforeChange is null.
assetAfterChange PhotoAssetChangeInfo | null No No Data of the media asset after change. In the case of asset deletion, assetAfterChange is null.
isContentChanged boolean No No Whether the content of the media asset is changed. true if changed, false otherwise.
isDeleted boolean No No Whether the media asset is deleted. true if deleted, false otherwise.

PhotoAssetChangeInfos20+

Describes the notification information about the change of a media asset.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
type NotifyChangeType No No Type of the media asset change.
assetChangeDatas PhotoAssetChangeData[] | null No No Array of changed media assets. If all media assets need to be queried again, assetChangeDatas is null.
isForRecheck boolean No No Whether the application should query all media assets again. true if the application should query all assets again, false otherwise.
NOTE
In scenarios involving bulk asset operations or abnormal notifications, isForRecheck will be true. In this case, the application should query all assets again.

AlbumChangeInfo20+

Describes the album information.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
albumType AlbumType No No Type of the album.
albumSubtype AlbumSubtype No No Subtype of the album.
albumName string No No Album name.
albumUri string No No URI of the album.
imageCount number No No Number of images in the album.
videoCount number No No Number of videos in the album.
count number No No Total number of assets in the album, including images and videos.
coverUri string No No URI of the album cover asset.

AlbumChangeData20+

Describes the detailed change data of an album.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
albumBeforeChange AlbumChangeInfo | null No No Data of the album before change. If an album is added, albumBeforeChange is null.
albumAfterChange AlbumChangeInfo | null No No Data of the album after change. In the case of album deletion, albumAfterChange is null.

AlbumChangeInfos20+

Describes the notification information about the change of an album.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
type NotifyChangeType No No Type of the album change.
albumChangeDatas AlbumChangeData[] | null No No Array of changed albums. If all albums need to be queried again, albumChangeDatas is null.
isForRecheck boolean No No Whether the application should query all albums again. true if the application should query all albums again, false otherwise.
NOTE
In scenarios involving bulk album operations or abnormal notifications, isForRecheck will be true. In this case, the application should query all albums again.

GridPinchMode23+

Represents the pinch mode of the grid in the picker.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 23.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
gridPinchModeType GridPinchModeType No Yes Grid pinch mode. If this parameter is set, the pinch function is supported. Otherwise, the pinch function is not supported.
defaultGridLevel GridLevel No Yes Grid level after the picker is started. The default value is STANDARD.

AssetCompatibleCapability24+

Defines the asset compatibility capability.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
supportedHighResolution boolean No No Whether high-resolution assets are supported. true: yes; false: no.
Atomic service API: This API can be used in atomic services since API version 24.
supportedMimeType Array<string> No Yes Supported MIME types.
- image/heic: The app supports the HEIF format.
- image/jpeg: The app supports only the JPEG format.
Since: 26.0.0
Atomic service API: This API can be used in atomic services since API version 26.0.0.

MediaLibraryAvailability

Defines the availability information of the media library.

Since: 26.0.0

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core

Name Type Read-Only Optional Description
availabilityStatus AvailabilityStatus No No Availability status of the media library.
unavailabilityReason string No No Reason why the media library is unavailable, for example, "Database corrupted".