openharmony 鸿蒙 changelogs-mediaLibrary

2023-06-24 浏览 (626)

File Management Subsystem Changelog

cl.file.1 mediaLibrary APIs Changed

The MediaLibrary class of the multimedia component is replaced by the FilePicker class.

Change Impact

For applications developed based on earlier versions, pay attention to the changes of APIs. FilePicker is a system application preset in OpenHarmony. You can use it to select and save files.

Key API/Component Changes

The APIs of MediaLibrary, located in @ohos.multimedia.medialibrary, are deprecated. The FilePicker class, located in @ohos.file.picker is used.

ModuleMethod/Attribute/Enum/ConstantChange Type
medialibraryfunction getMediaLibrary(): MediaLibrary;Deprecated
medialibraryfunction getMediaLibrary(context: Context): MediaLibrary;Deprecated
medialibraryfunction getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): voidDeprecated
medialibraryfunction getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>Deprecated
medialibraryfunction on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback: Callback<void>): voidDeprecated
medialibraryfunction off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback?: Callback<void>): voidDeprecated
medialibraryfunction createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback<FileAsset>): voidDeprecated
medialibraryfunction createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise<FileAsset>Deprecated
medialibraryfunction deleteAsset(uri: string): Promise<void>Deprecated
medialibraryfunction deleteAsset(uri: string, callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>): voidDeprecated
medialibraryfunction getPublicDirectory(type: DirectoryType): Promise<string>Deprecated
medialibraryfunction getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album>>): voidDeprecated
medialibraryfunction getAlbums(options: MediaFetchOptions): Promise<Array<Album>>Deprecated
medialibraryfunction release(callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction release(): Promise<void>Deprecated
medialibraryfunction storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>): voidDeprecated
medialibraryfunction storeMediaAsset(option: MediaAssetOption): Promise<string>Deprecated
medialibraryfunction startImagePreview(images: Array<string>, index: number, callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction startImagePreview(images: Array<string>, callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction startImagePreview(images: Array<string>, index?: number): Promise<void>Deprecated
medialibraryfunction startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<string>>): voidDeprecated
medialibraryfunction startMediaSelect(option: MediaSelectOption): Promise<Array<string>>Deprecated
medialibraryfunction getActivePeers(): Promise<Array<PeerInfo>>;Deprecated
medialibraryfunction getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void;Deprecated
medialibraryfunction getAllPeers(): Promise<Array<PeerInfo>>;Deprecated
medialibraryfunction FileAsset.isDirectory(callback: AsyncCallback<boolean>): voidDeprecated
medialibraryfunction FileAsset.isDirectory():Promise<boolean>Deprecated
medialibraryfunction FileAsset.commitModify(callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction FileAsset.commitModify(): Promise<void>Deprecated
medialibraryfunction FileAsset.open(mode: string, callback: AsyncCallback<number>): voidDeprecated
medialibraryfunction FileAsset.open(mode: string): Promise<number>Deprecated
medialibraryfunction FileAsset.close(fd: number, callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction FileAsset.close(fd: number): Promise<void>Deprecated
medialibraryfunction FileAsset.getThumbnail(callback: AsyncCallback<image.PixelMap>): voidDeprecated
medialibraryfunction FileAsset.getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): voidDeprecated
medialibraryfunction FileAsset.getThumbnail(size?: Size): Promise<image.PixelMap>Deprecated
medialibraryfunction FileAsset.favorite(isFavorite: boolean, callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction FileAsset.favorite(isFavorite: boolean): Promise<void>Deprecated
medialibraryfunction FileAsset.isFavorite(callback: AsyncCallback<boolean>): voidDeprecated
medialibraryfunction FileAsset.isFavorite():Promise<boolean>Deprecated
medialibraryfunction FileAsset.trash(isTrash: boolean, callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction FileAsset.trash(isTrash: boolean): Promise<void>Deprecated
medialibraryfunction FileAsset.isTrash(callback: AsyncCallback<boolean>): voidDeprecated
medialibraryfunction FileAsset.isTrash():Promise<boolean>Deprecated
medialibraryfunction FetchFileResult.getCount(): numberDeprecated
medialibraryfunction FetchFileResult.isAfterLast(): booleanDeprecated
medialibraryfunction FetchFileResult.close(): voidDeprecated
medialibraryfunction FetchFileResult.getFirstObject(callback: AsyncCallback<FileAsset>): voidDeprecated
medialibraryfunction FetchFileResult.getFirstObject(): Promise<FileAsset>Deprecated
medialibraryfunction FetchFileResult.getNextObject(callback: AsyncCallback<FileAsset>): voidDeprecated
medialibraryfunction FetchFileResult.getNextObject(): Promise<FileAsset>Deprecated
medialibraryfunction FetchFileResult.getLastObject(callback: AsyncCallback<FileAsset>): voidDeprecated
medialibraryfunction FetchFileResult.getLastObject(): Promise<FileAsset>Deprecated
medialibraryfunction FetchFileResult.getPositionObject(index: number, callback: AsyncCallback<FileAsset>): voidDeprecated
medialibraryfunction FetchFileResult.getPositionObject(index: number): Promise<FileAsset>Deprecated
medialibraryfunction FetchFileResult.getAllObject(callback: AsyncCallback<Array<FileAsset>>): voidDeprecated
medialibraryfunction FetchFileResult.getAllObject(): Promise<Array<FileAsset>>Deprecated
medialibraryfunction Album.commitModify(callback: AsyncCallback<void>): voidDeprecated
medialibraryfunction Album.commitModify(): Promise<void>Deprecated
medialibraryfunction Album.getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): voidDeprecated
medialibraryfunction Album.getFileAssets(options?: MediaFetchOptions): Promise<FetchFileResult>Deprecated
medialibraryenum DeviceTypeDeprecated
medialibraryenum FileKeyDeprecated
medialibraryenum DirectoryTypeDeprecated
medialibraryenum MediaTypeDeprecated
medialibraryinterface PeerInfoDeprecated
medialibraryinterface SizeDeprecated
medialibraryinterface MediaFetchOptionsDeprecated
medialibraryinterface MediaAssetOptionDeprecated
medialibraryinterface MediaSelectOptionDeprecated
medialibraryinterface FileAssetDeprecated

Adaptation Guide

For example, refer to the code snippet below to call an API to select an image:

import picker from '@ohos.file.picker';

async function example() {
    try {  
        let PhotoSelectOptions = new picker.PhotoSelectOptions();
        PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
        PhotoSelectOptions.maxSelectNumber = 1;
        let photoPicker = new picker.PhotoViewPicker();
        photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => {
            if (PhotoSelectResult !== undefined) {
                console.info("PhotoViewPicker.select pass, PhotoSelectResult uri: " + JSON.stringify(PhotoSelectResult));
            } else {
                console.error("PhotoViewPicker.select PhotoSelectResult is undefined");
            }
        }).catch((err) => {
            console.error("PhotoViewPicker.select fail, err: " + err);
        });
    } catch (err) {
        console.error("PhotoViewPicker fail, err: " + err);
    }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Readme

harmony 鸿蒙Example Subsystem Changelog

harmony 鸿蒙Ability Framework Changelog

harmony 鸿蒙Account Subsystem Changelog

harmony 鸿蒙ArkUI Subsystem ChangeLog

harmony 鸿蒙Multimedia Subsystem Changelog

harmony 鸿蒙Common Library Subsystem Changelog

harmony 鸿蒙Distributed Data Management Subsystem JS API Changelog

harmony 鸿蒙File Management Subsystem Changelog

harmony 鸿蒙Input Method Framework ChangeLog

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/c4a98383967946979ca3fd48db2141d6