• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 文件子系统ChangeLog
2
3## cl.file.1 mediaLibrary相关接口变更
4
5multimedia 部件 medialibrary 接口废弃原有相关接口,使用 FilePicker 替代。
6
7**变更影响**
8
9基于此前版本开发的应用,需注意废弃接口的迭代更新。替代的 FilePicker 应用是OpenHarmony中预置的系统应用,为用户提供文件选择及保存功能。
10
11**关键接口/组件变更**
12
13medialibrary 相关接口废弃,原接口位于 @ohos.multimedia.medialibrary;替代应用为 FilePicker,位于[@ohos.file.picker](https://gitee.com/openharmony/interface_sdk-js/blob/master/api/@ohos.file.picker.d.ts)
14
15| 模块名                    | 方法/属性/枚举/常量                                          | 变更类型 |
16| ------------------------- | ------------------------------------------------------------ | -------- |
17| medialibrary   |  **function** getMediaLibrary(): MediaLibrary; | 废弃     |
18| medialibrary   |  **function** getMediaLibrary(context: Context): MediaLibrary; | 废弃     |
19| medialibrary   |  **function** getFileAssets(options: MediaFetchOptions, callback: AsyncCallback\<FetchFileResult\>): void | 废弃     |
20| medialibrary   |  **function** getFileAssets(options: MediaFetchOptions): Promise\<FetchFileResult\> | 废弃     |
21| medialibrary   |  **function** on(type: 'deviceChange'\|'albumChange'\|'imageChange'\|'audioChange'\|'videoChange'\|'fileChange'\|'remoteFileChange', callback: Callback\<void\>): void | 废弃     |
22| medialibrary   |  **function** off(type: 'deviceChange'\|'albumChange'\|'imageChange'\|'audioChange'\|'videoChange'\|'fileChange'\|'remoteFileChange', callback?: Callback\<void\>): void | 废弃     |
23| medialibrary   |  **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback\<FileAsset\>): void | 废弃     |
24| medialibrary   |  **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise\<FileAsset\> | 废弃     |
25| medialibrary   |  **function** deleteAsset(uri: string): Promise\<void\> | 废弃     |
26| medialibrary   |  **function** deleteAsset(uri: string, callback: AsyncCallback\<void\>): void | 废弃     |
27| medialibrary   |  **function** getPublicDirectory(type: DirectoryType, callback: AsyncCallback\<string\>): void | 废弃     |
28| medialibrary   |  **function** getPublicDirectory(type: DirectoryType): Promise\<string\> | 废弃     |
29| medialibrary   |  **function** getAlbums(options: MediaFetchOptions, callback: AsyncCallback\<Array\<Album\>\>): void | 废弃     |
30| medialibrary   |  **function** getAlbums(options: MediaFetchOptions): Promise\<Array\<Album\>\> | 废弃     |
31| medialibrary   |  **function** release(callback: AsyncCallback\<void\>): void  | 废弃     |
32| medialibrary   |  **function** release(): Promise\<void\> | 废弃     |
33| medialibrary   |  **function** storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback\<string\>): void | 废弃     |
34| medialibrary   |  **function** storeMediaAsset(option: MediaAssetOption): Promise\<string\> | 废弃     |
35| medialibrary   |  **function** startImagePreview(images: Array\<string\>, index: number, callback: AsyncCallback\<void\>): void | 废弃     |
36| medialibrary   |  **function** startImagePreview(images: Array\<string\>, callback: AsyncCallback\<void\>): void | 废弃     |
37| medialibrary   |  **function** startImagePreview(images: Array\<string\>, index?: number): Promise\<void\> | 废弃     |
38| medialibrary   |  **function** startMediaSelect(option: MediaSelectOption, callback: AsyncCallback\<Array\<string\>\>): void | 废弃     |
39| medialibrary   |  **function** startMediaSelect(option: MediaSelectOption): Promise\<Array\<string\>\> | 废弃     |
40| medialibrary   |  **function** getActivePeers(): Promise\<Array\<PeerInfo\>\>; | 废弃     |
41| medialibrary   |  **function** getActivePeers(callback: AsyncCallback\<Array\<PeerInfo\>\>): void; | 废弃     |
42| medialibrary   |  **function** getAllPeers(): Promise\<Array\<PeerInfo\>\>; | 废弃     |
43| medialibrary   |  **function** FileAsset.isDirectory(callback: AsyncCallback\<boolean\>): void | 废弃     |
44| medialibrary   |  **function** FileAsset.isDirectory():Promise\<boolean\> | 废弃     |
45| medialibrary   |  **function** FileAsset.commitModify(callback: AsyncCallback\<void\>): void | 废弃     |
46| medialibrary   |  **function** FileAsset.commitModify(): Promise\<void\> | 废弃     |
47| medialibrary   |  **function** FileAsset.open(mode: string, callback: AsyncCallback\<number\>): void | 废弃     |
48| medialibrary   |  **function** FileAsset.open(mode: string): Promise\<number\> | 废弃     |
49| medialibrary   |  **function** FileAsset.close(fd: number, callback: AsyncCallback\<void\>): void | 废弃     |
50| medialibrary   |  **function** FileAsset.close(fd: number): Promise\<void\> | 废弃     |
51| medialibrary   |  **function** FileAsset.getThumbnail(callback: AsyncCallback\<image.PixelMap\>): void | 废弃     |
52| medialibrary   |  **function** FileAsset.getThumbnail(size: Size, callback: AsyncCallback\<image.PixelMap\>): void | 废弃     |
53| medialibrary   |  **function** FileAsset.getThumbnail(size?: Size): Promise\<image.PixelMap\> | 废弃     |
54| medialibrary   |  **function** FileAsset.favorite(isFavorite: boolean, callback: AsyncCallback\<void\>): void | 废弃     |
55| medialibrary   |  **function** FileAsset.favorite(isFavorite: boolean): Promise\<void\> | 废弃     |
56| medialibrary   |  **function** FileAsset.isFavorite(callback: AsyncCallback\<boolean\>): void | 废弃     |
57| medialibrary   |  **function** FileAsset.isFavorite():Promise\<boolean\>  | 废弃     |
58| medialibrary   |  **function** FileAsset.trash(isTrash: boolean, callback: AsyncCallback\<void\>): void | 废弃     |
59| medialibrary   |  **function** FileAsset.trash(isTrash: boolean): Promise\<void\> | 废弃     |
60| medialibrary   |  **function** FileAsset.isTrash(callback: AsyncCallback\<boolean\>): void | 废弃     |
61| medialibrary   |  **function** FileAsset.isTrash():Promise\<boolean\> | 废弃     |
62| medialibrary   |  **function** FetchFileResult.getCount(): number | 废弃     |
63| medialibrary   |  **function** FetchFileResult.isAfterLast(): boolean | 废弃     |
64| medialibrary   |  **function** FetchFileResult.close(): void | 废弃     |
65| medialibrary   |  **function** FetchFileResult.getFirstObject(callback: AsyncCallback\<FileAsset\>): void | 废弃     |
66| medialibrary   |  **function** FetchFileResult.getFirstObject(): Promise\<FileAsset\> | 废弃     |
67| medialibrary   |  **function** FetchFileResult.getNextObject(callback: AsyncCallback\<FileAsset\>): void | 废弃     |
68| medialibrary   |  **function** FetchFileResult.getNextObject(): Promise\<FileAsset\> | 废弃     |
69| medialibrary   |  **function** FetchFileResult.getLastObject(callback: AsyncCallback\<FileAsset\>): void | 废弃     |
70| medialibrary   |  **function** FetchFileResult.getLastObject(): Promise\<FileAsset\> | 废弃     |
71| medialibrary   |  **function** FetchFileResult.getPositionObject(index: number, callback: AsyncCallback\<FileAsset\>): void | 废弃     |
72| medialibrary   |  **function** FetchFileResult.getPositionObject(index: number): Promise\<FileAsset\> | 废弃     |
73| medialibrary   |  **function** FetchFileResult.getAllObject(callback: AsyncCallback\<Array\<FileAsset\>\>): void | 废弃     |
74| medialibrary   |  **function** FetchFileResult.getAllObject(): Promise\<Array\<FileAsset\>\> | 废弃     |
75| medialibrary   |  **function** Album.commitModify(callback: AsyncCallback\<void\>): void | 废弃     |
76| medialibrary   |  **function** Album.commitModify(): Promise\<void\> | 废弃     |
77| medialibrary   |  **function** Album.getFileAssets(options: MediaFetchOptions, callback: AsyncCallback\<FetchFileResult\>): void | 废弃     |
78| medialibrary   |  **function** Album.getFileAssets(options?: MediaFetchOptions): Promise\<FetchFileResult\> | 废弃     |
79| medialibrary   |  **enum** DeviceType | 废弃     |
80| medialibrary   |  **enum** FileKey | 废弃     |
81| medialibrary   |  **enum** DirectoryType | 废弃     |
82| medialibrary   |  **enum** MediaType | 废弃     |
83| medialibrary   |  **interface** PeerInfo | 废弃     |
84| medialibrary   |  **interface** Size  | 废弃     |
85| medialibrary   |  **interface** MediaFetchOptions | 废弃     |
86| medialibrary   |  **interface** MediaAssetOption | 废弃     |
87| medialibrary   |  **interface** MediaSelectOption | 废弃     |
88| medialibrary   |  **interface** FileAsset | 废弃     |
89
90**适配指导**
91
92以选取一张图片为例,在替代应用中如下方式进行调用:
93
94```js
95import picker from '@ohos.file.picker';
96
97async function example() {
98    try {
99        let PhotoSelectOptions = new picker.PhotoSelectOptions();
100        PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
101        PhotoSelectOptions.maxSelectNumber = 1;
102        let photoPicker = new picker.PhotoViewPicker();
103        photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => {
104            if (PhotoSelectResult !== undefined) {
105                console.info("PhotoViewPicker.select pass, PhotoSelectResult uri: " + JSON.stringify(PhotoSelectResult));
106            } else {
107                console.error("PhotoViewPicker.select PhotoSelectResult is undefined");
108            }
109        }).catch((err) => {
110            console.error("PhotoViewPicker.select fail, err: " + err);
111        });
112    } catch (err) {
113        console.error("PhotoViewPicker fail, err: " + err);
114    }
115}
116```