提交 ca7bab1a 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 13a7dc63
...@@ -4,7 +4,7 @@ The **photoAccessHelper** module provides APIs for album management, including c ...@@ -4,7 +4,7 @@ The **photoAccessHelper** module provides APIs for album management, including c
> **NOTE** > **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. > 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 ## Modules to Import
...@@ -341,7 +341,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -341,7 +341,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod
| ID| Error Message| | ID| Error Message|
| -------- | ---------------------------------------- | | -------- | ---------------------------------------- |
| 202 | Called by non-system application. | | 202 | Called by non-system application. |
| 401 | if type displayName is not string. | | 401 | if type displayName is not string. |
| 14000001 | if type of displayName is invalid. | | 14000001 | if type of displayName is invalid. |
...@@ -401,9 +401,9 @@ async function example() { ...@@ -401,9 +401,9 @@ async function example() {
let options = { let options = {
title: 'testPhoto' title: 'testPhoto'
} }
phAccessHelper.createAsset(photoType, extension, options, (err, photoAsset) => { phAccessHelper.createAsset(photoType, extension, options, (err, uri) => {
if (photoAsset != undefined) { if (uri != undefined) {
console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset uri' + uri);
console.info('createAsset successfully'); console.info('createAsset successfully');
} else { } else {
console.error('createAsset failed, message = ', err); console.error('createAsset failed, message = ', err);
...@@ -445,9 +445,9 @@ async function example() { ...@@ -445,9 +445,9 @@ async function example() {
console.info('createAssetDemo'); console.info('createAssetDemo');
let photoType = photoAccessHelper.PhotoType.IMAGE; let photoType = photoAccessHelper.PhotoType.IMAGE;
let extension = 'jpg'; let extension = 'jpg';
phAccessHelper.createAsset(photoType, extension, (err, photoAsset) => { phAccessHelper.createAsset(photoType, extension, (err, uri) => {
if (photoAsset != undefined) { if (uri != undefined) {
console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset uri' + uri);
console.info('createAsset successfully'); console.info('createAsset successfully');
} else { } else {
console.error('createAsset failed, message = ', err); console.error('createAsset failed, message = ', err);
...@@ -499,8 +499,8 @@ async function example() { ...@@ -499,8 +499,8 @@ async function example() {
let options = { let options = {
title: 'testPhoto' title: 'testPhoto'
} }
let photoAsset = await phAccessHelper.createAsset(photoType,extension, options); let uri = await phAccessHelper.createAsset(photoType, extension, options);
console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset uri' + uri);
console.info('createAsset successfully'); console.info('createAsset successfully');
} catch (err) { } catch (err) {
console.error('createAsset failed, message = ', err); console.error('createAsset failed, message = ', err);
...@@ -1077,15 +1077,15 @@ async function example() { ...@@ -1077,15 +1077,15 @@ async function example() {
//file had changed, do something //file had changed, do something
} }
// Register onCallback1. // Register onCallback1.
phAccessHelper.registerChange(photoAsset.uri, false, onCallback1); phAccessHelper.registerChange(photoAsset.uri, false, onCallback1);
// Register onCallback2. // Register onCallback2.
phAccessHelper.registerChange(photoAsset.uri, false, onCallback2); phAccessHelper.registerChange(photoAsset.uri, false, onCallback2);
photoAsset.favorite(true, (err) => { photoAsset.setFavorite(true, (err) => {
if (err == undefined) { if (err == undefined) {
console.info('favorite successfully'); console.info('setFavorite successfully');
} else { } else {
console.error('favorite failed with error:' + err); console.error('setFavorite failed with error:' + err);
} }
}); });
} }
...@@ -1145,11 +1145,11 @@ async function example() { ...@@ -1145,11 +1145,11 @@ async function example() {
phAccessHelper.registerChange(photoAsset.uri, false, onCallback2); phAccessHelper.registerChange(photoAsset.uri, false, onCallback2);
// Unregister the listening of onCallback1. // Unregister the listening of onCallback1.
phAccessHelper.unRegisterChange(photoAsset.uri, onCallback1); phAccessHelper.unRegisterChange(photoAsset.uri, onCallback1);
photoAsset.favorite(true, (err) => { photoAsset.setFavorite(true, (err) => {
if (err == undefined) { if (err == undefined) {
console.info('favorite successfully'); console.info('setFavorite successfully');
} else { } else {
console.error('favorite failed with error:' + err); console.error('setFavorite failed with error:' + err);
} }
}); });
} }
...@@ -1539,7 +1539,7 @@ For details about the error codes, see [Universal Error Codes](../errorcodes/err ...@@ -1539,7 +1539,7 @@ For details about the error codes, see [Universal Error Codes](../errorcodes/err
| -------- | ---------------------------------------- | | -------- | ---------------------------------------- |
| 401 | if values to commit is invalid. | | 401 | if values to commit is invalid. |
**Example** **Example**
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
...@@ -2839,7 +2839,7 @@ Obtains image and video assets. This API uses an asynchronous callback to return ...@@ -2839,7 +2839,7 @@ Obtains image and video assets. This API uses an asynchronous callback to return
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- | | -------- | ------------------------- | ---- | ---------- |
| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the album files.| | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the albums.|
| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[PhotoAsset](#photoasset)&gt;&gt; | Yes | Callback invoked to return the image and video assets obtained.| | callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[PhotoAsset](#photoasset)&gt;&gt; | Yes | Callback invoked to return the image and video assets obtained.|
**Error codes** **Error codes**
...@@ -2856,17 +2856,17 @@ For details about the error codes, see [Universal Error Codes](../errorcodes/err ...@@ -2856,17 +2856,17 @@ For details about the error codes, see [Universal Error Codes](../errorcodes/err
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() { async function example() {
console.info('albumGetPhotoAssetsDemoCallback'); console.info('albumGetAssetsDemoCallback');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = { let albumFetchOptions = {
fetchColumns: [],
predicates: predicates predicates: predicates
}; };
let fetchOption = { let fetchOption = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
const albumList = await phAccessHelper.getAlbums(albumFetchOptions); const albumList = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
const album = await albumList.getFirstObject(); const album = await albumList.getFirstObject();
album.getAssets(fetchOption, (err, albumFetchResult) => { album.getAssets(fetchOption, (err, albumFetchResult) => {
if (albumFetchResult != undefined) { if (albumFetchResult != undefined) {
...@@ -2914,17 +2914,18 @@ For details about the error codes, see [Universal Error Codes](../errorcodes/err ...@@ -2914,17 +2914,18 @@ For details about the error codes, see [Universal Error Codes](../errorcodes/err
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() { async function example() {
console.info('albumGetPhotoAssetsDemoPromise'); console.info('albumGetAssetsDemoPromise');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = { let albumFetchOptions = {
fetchColumns: [],
predicates: predicates predicates: predicates
}; };
let fetchOption = { let fetchOption = {
fetchColumns: [], fetchColumns: [],
predicates: predicates predicates: predicates
}; };
const albumList = await phAccessHelper.getAlbums(albumFetchOptions); const albumList = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
const album = await albumList.getFirstObject(); const album = await albumList.getFirstObject();
album.getAssets(fetchOption).then((albumFetchResult) => { album.getAssets(fetchOption).then((albumFetchResult) => {
console.info('album getPhotoAssets successfully, getCount: ' + albumFetchResult.getCount()); console.info('album getPhotoAssets successfully, getCount: ' + albumFetchResult.getCount());
...@@ -2967,9 +2968,10 @@ async function example() { ...@@ -2967,9 +2968,10 @@ async function example() {
console.info('albumCommitModifyDemo'); console.info('albumCommitModifyDemo');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = { let albumFetchOptions = {
fetchColumns: [],
predicates: predicates predicates: predicates
}; };
const albumList = await phAccessHelper.getAlbums(albumFetchOptions); const albumList = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
const album = await albumList.getFirstObject(); const album = await albumList.getFirstObject();
album.albumName = 'hello'; album.albumName = 'hello';
album.commitModify((err) => { album.commitModify((err) => {
...@@ -3015,9 +3017,10 @@ async function example() { ...@@ -3015,9 +3017,10 @@ async function example() {
console.info('albumCommitModifyDemo'); console.info('albumCommitModifyDemo');
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = { let albumFetchOptions = {
fetchColumns: [],
predicates: predicates predicates: predicates
}; };
const albumList = await phAccessHelper.getAlbums(albumFetchOptions); const albumList = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
const album = await albumList.getFirstObject(); const album = await albumList.getFirstObject();
album.albumName = 'hello'; album.albumName = 'hello';
album.commitModify().then(() => { album.commitModify().then(() => {
...@@ -3496,6 +3499,131 @@ async function example() { ...@@ -3496,6 +3499,131 @@ async function example() {
} }
``` ```
### setCoverUri
setCoverUri(uri: string, callback: AsyncCallback&lt;void&gt;): void;
Sets the album cover. This API uses an asynchronous callback to return the result.
**NOTE**<br>This API can be used to set the user album cover, but not the system album cover.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes | URI of the file to be set as the album cover.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 202 | Called by non-system application. |
| 401 | if parameter is invalid. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setCoverUriDemoCallback');
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOption = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC);
let album = await albumFetchResult.getFirstObject();
let fetchResult = await album.getAssets(fetchOption);
let asset = await fetchResult.getFirstObject();
album.setCoverUri(asset.uri, (err) => {
if (err === undefined) {
console.info('album setCoverUri successfully');
} else {
console.error('album setCoverUri failed with error: ' + err);
}
});
} catch (err) {
console.error('setCoverUriDemoCallback failed with error: ' + err);
}
}
```
### setCoverUri
setCoverUri(uri: string): Promise&lt;void&gt;;
Sets the album cover. This API uses a promise to return the result.
**NOTE**<br>This API can be used to set the user album cover, but not the system album cover.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes | URI of the file to be set as the album cover.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 202 | Called by non-system application. |
| 401 | if parameter is invalid. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setCoverUriDemoCallback');
let predicates = new dataSharePredicates.DataSharePredicates();
let fetchOption = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC);
let album = await albumFetchResult.getFirstObject();
let fetchResult = await album.getAssets(fetchOption);
let asset = await fetchResult.getFirstObject();
album.setCoverUri(asset.uri, (err) => {
if (err === undefined) {
console.info('album setCoverUri successfully');
} else {
console.error('album setCoverUri failed with error: ' + err);
}
});
} catch (err) {
console.error('setCoverUriDemoCallback failed with error: ' + err);
}
}
```
## MemberType ## MemberType
Enumerates the member types. Enumerates the member types.
...@@ -3597,6 +3725,7 @@ Defines the key information about an image or video file. ...@@ -3597,6 +3725,7 @@ Defines the key information about an image or video file.
| POSITION | 'position' | File location type. **System API**: This is a system API. | | POSITION | 'position' | File location type. **System API**: This is a system API. |
| DATE_TRASHED | 'date_trashed' | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. **System API**: This is a system API. | | DATE_TRASHED | 'date_trashed' | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. **System API**: This is a system API. |
| HIDDEN | 'hidden' | Whether the file is hidden. **System API**: This is a system API. | | HIDDEN | 'hidden' | Whether the file is hidden. **System API**: This is a system API. |
| CAMERA_SHOT_KEY | 'camera_shot_key' | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.)<br/>**System API**: This is a system API. |
## AlbumKeys ## AlbumKeys
...@@ -3618,6 +3747,7 @@ Defines the options for creating an image or video asset. ...@@ -3618,6 +3747,7 @@ Defines the options for creating an image or video asset.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ | | ---------------------- | ------------------- | ---- | ------------------------------------------------ |
| subtype | [PhotoSubtype](#photosubtype) | No | Subtype of the image or video. **System API**: This is a system API. | | subtype | [PhotoSubtype](#photosubtype) | No | Subtype of the image or video. **System API**: This is a system API. |
| cameraShotKey | string | No | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.)<br/>**System API**: This is a system API. |
## CreateOptions ## CreateOptions
......
...@@ -481,113 +481,6 @@ async function example() { ...@@ -481,113 +481,6 @@ async function example() {
} }
``` ```
### getPhotoAlbums
getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback&lt;FetchResult&lt;Album&gt;&gt;): void;
Obtains image and video albums. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. |
| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Yes | Callback invoked to return the image and video albums obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13900020 | if type options is not AlbumFetchOptions. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoAlbumsDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = {
predicates: predicates
};
mgr.getPhotoAlbums(albumFetchOptions, (err, fetchResult) => {
if (fetchResult != undefined) {
console.info('albums.count = ' + fetchResult.getCount());
fetchResult.getFirstObject((err, album) => {
if (album != undefined) {
console.info('first album.albumName = ' + album.albumName);
} else {
console.error('album is undefined, err = ', err);
}
});
} else {
console.error('getPhotoAlbums fail, message = ', err);
}
});
}
```
### getPhotoAlbums
getPhotoAlbums(options: AlbumFetchOptions): Promise&lt;FetchResult&lt;Album&gt;&gt;;
Obtains image and video albums. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Promise used to return the image and video albums obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13900020 | if type options is not AlbumFetchOptions. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoAlbumsDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = {
predicates: predicates
};
try {
let fetchResult = await mgr.getPhotoAlbums(albumFetchOptions);
console.info('album.count = ' + fetchResult.getCount());
const album = await fetchResult.getFirstObject();
console.info('first album.albumName = ' + album.albumName);
} catch (err) {
console.error('getPhotoAlbums fail, message = ' + err);
}
}
```
### createAlbum<sup>10+</sup> ### createAlbum<sup>10+</sup>
createAlbum(name: string, callback: AsyncCallback&lt;Album&gt;): void; createAlbum(name: string, callback: AsyncCallback&lt;Album&gt;): void;
...@@ -935,12 +828,124 @@ async function example() { ...@@ -935,12 +828,124 @@ async function example() {
} }
``` ```
### getPhotoAlbums
getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback&lt;FetchResult&lt;Album&gt;&gt;): void;
Obtains image and video albums. This API uses an asynchronous callback to return the result.
This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. |
| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Yes | Callback invoked to return the image and video albums obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13900020 | if type options is not AlbumFetchOptions. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoAlbumsDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = {
predicates: predicates
};
mgr.getPhotoAlbums(albumFetchOptions, (err, fetchResult) => {
if (fetchResult != undefined) {
console.info('albums.count = ' + fetchResult.getCount());
fetchResult.getFirstObject((err, album) => {
if (album != undefined) {
console.info('first album.albumName = ' + album.albumName);
} else {
console.error('album is undefined, err = ', err);
}
});
} else {
console.error('getPhotoAlbums fail, message = ', err);
}
});
}
```
### getPhotoAlbums
getPhotoAlbums(options: AlbumFetchOptions): Promise&lt;FetchResult&lt;Album&gt;&gt;;
Obtains image and video albums. This API uses a promise to return the result.
This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Promise used to return the image and video albums obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 13900020 | if type options is not AlbumFetchOptions. |
**Example**
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('getPhotoAlbumsDemo');
let predicates = new dataSharePredicates.DataSharePredicates();
let albumFetchOptions = {
predicates: predicates
};
try {
let fetchResult = await mgr.getPhotoAlbums(albumFetchOptions);
console.info('album.count = ' + fetchResult.getCount());
const album = await fetchResult.getFirstObject();
console.info('first album.albumName = ' + album.albumName);
} catch (err) {
console.error('getPhotoAlbums fail, message = ' + err);
}
}
```
### getPrivateAlbum ### getPrivateAlbum
getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback&lt;FetchResult&lt;PrivateAlbum&gt;&gt;): void; getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback&lt;FetchResult&lt;PrivateAlbum&gt;&gt;): void;
Obtains the system album. This API uses an asynchronous callback to return the result. Obtains the system album. This API uses an asynchronous callback to return the result.
This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO **Required permissions**: ohos.permission.READ_IMAGEVIDEO
...@@ -982,6 +987,8 @@ getPrivateAlbum(type: PrivateAlbumType): Promise&lt;FetchResult&lt;PrivateAlbum& ...@@ -982,6 +987,8 @@ getPrivateAlbum(type: PrivateAlbumType): Promise&lt;FetchResult&lt;PrivateAlbum&
Obtains the system album. This API uses a promise to return the result. Obtains the system album. This API uses a promise to return the result.
This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO **Required permissions**: ohos.permission.READ_IMAGEVIDEO
...@@ -1252,102 +1259,6 @@ async function example() { ...@@ -1252,102 +1259,6 @@ async function example() {
} }
``` ```
### on
on(type: ChangeEvent, callback: Callback&lt;void&gt;): void
Subscribes to changes of the file management library. This API uses a callback to return the result.
This API will be deprecated. Use [on<sup>10+</sup>](#on10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.<br>**deviceChange** indicates the device change.<br>**albumChange** indicates the album change.<br>**imageChange** indicates the image change.<br>**audioChange** indicates the audio file change.<br>**videoChange** indicates the video file change.<br>**remoteFileChange** indicates the file change on the registered device.|
| callback | Callback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```ts
async function example() {
console.info('onDemo');
let count = 0;
mgr.on('imageChange', () => {
count++;
// Image file changed. Do something.
});
try {
let testFileName = 'testFile' + Date.now() + '.jpg';
let fileAsset = await mgr.createPhotoAsset(testFileName);
console.info('createPhotoAsset file displayName' + fileAsset.displayName);
console.info('createPhotoAsset successfully');
} catch (err) {
console.error('createPhotoAsset failed, message = ' + err);
}
// Sleep 1s.
if (count > 0) {
console.info('onDemo success');
} else {
console.error('onDemo fail');
}
mgr.off('imageChange', () => {
// Unsubscription succeeds.
});
}
```
### off
off(type: ChangeEvent, callback?: Callback&lt;void&gt;): void
Unsubscribes from changes of the file management library. This API uses a callback to return the result.
This API will be deprecated. Use [off<sup>10+</sup>](#off10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.<br>**deviceChange** indicates the device change.<br>**albumChange** indicates the album change.<br>**imageChange** indicates the image change.<br>**audioChange** indicates the audio file change.<br>**videoChange** indicates the video file change.<br>**remoteFileChange** indicates the change of the file on a registered device.|
| callback | Callback&lt;void&gt; | No | Callback that returns no value. |
**Example**
```ts
async function example() {
console.info('offDemo');
let count = 0;
mgr.on('imageChange', () => {
count++;
// Image file changed. Do something.
});
mgr.off('imageChange', () => {
// Unsubscription succeeds.
});
try {
let testFileName = 'testFile' + Date.now() + '.jpg';
let fileAsset = await mgr.createPhotoAsset(testFileName);
console.info('createPhotoAsset file displayName' + fileAsset.displayName);
console.info('createPhotoAsset successfully');
} catch (err) {
console.error('createPhotoAsset failed, message = ' + err);
}
// Sleep 1s.
if (count == 0) {
console.info('offDemo success');
} else {
console.error('offDemo fail');
}
}
```
### getActivePeers ### getActivePeers
getActivePeers(callback: AsyncCallback&lt;Array&lt;PeerInfo&gt;&gt;): void; getActivePeers(callback: AsyncCallback&lt;Array&lt;PeerInfo&gt;&gt;): void;
...@@ -1427,7 +1338,7 @@ Obtains information about all peer devices. This API uses an asynchronous callba ...@@ -1427,7 +1338,7 @@ Obtains information about all peer devices. This API uses an asynchronous callba
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ------------ | | -------- | --------------------------------- | ---- | ------------ |
| callback | AsyncCallback&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Yes | Callback invoked to return the information obtained.| | callback | AsyncCallback&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Yes | Callback invoked to return the peer device information obtained.|
**Example** **Example**
...@@ -1545,7 +1456,7 @@ async function example() { ...@@ -1545,7 +1456,7 @@ async function example() {
on(uri: string, forSubUri: boolean, callback: Callback&lt;ChangeData&gt;) : void on(uri: string, forSubUri: boolean, callback: Callback&lt;ChangeData&gt;) : void
Enables listening for the specified URI. This API uses a callback to return the result. Registers a listener for the specified URI.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -1591,7 +1502,7 @@ async function example() { ...@@ -1591,7 +1502,7 @@ async function example() {
// File changed. Do something. // File changed. Do something.
} }
// Register onCallback1. // Register onCallback1.
mgr.on(fileAsset.uri, false, onCallback1); mgr.on(fileAsset.uri, false, onCallback1);
// Register onCallback2. // Register onCallback2.
mgr.on(fileAsset.uri, false, onCallback2); mgr.on(fileAsset.uri, false, onCallback2);
...@@ -1609,7 +1520,7 @@ async function example() { ...@@ -1609,7 +1520,7 @@ async function example() {
off(uri: string, callback?: Callback&lt;ChangeData&gt;): void off(uri: string, callback?: Callback&lt;ChangeData&gt;): void
Disables listening for the specified URI. Multiple callbacks can be registered for a URI for listening. You can use **off()** to disable the listening of the specified callbacks or all callbacks. Unregisters the listener for the specified URI. Multiple callbacks can be registered for a URI for listening. You can use this API to unregister the specified callbacks or all callbacks.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -1618,7 +1529,7 @@ Disables listening for the specified URI. Multiple callbacks can be registered f ...@@ -1618,7 +1529,7 @@ Disables listening for the specified URI. Multiple callbacks can be registered f
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| uri | string | Yes | URI of the file asset or album, or [DefaultChangeUri](#defaultchangeuri10).| | uri | string | Yes | URI of the file asset or album, or [DefaultChangeUri](#defaultchangeuri10).|
| callback | Callback&lt;[ChangeData](#changedata10)&gt; | No | Callback registered by [on<sup>10+</sup>](#on10). If this parameter is not specified, all callbacks registered for the URI will be unregistered. <br>**NOTE**: The specified callback will not be invoked.| | callback | Callback&lt;[ChangeData](#changedata10)&gt; | No | Callback registered by [on<sup>10+</sup>](#on10). If this parameter is not specified, all listener callbacks registered for the URI will be unregistered. <br>**NOTE**: The specified callback will not be invoked.|
**Error codes** **Error codes**
...@@ -1667,6 +1578,102 @@ async function example() { ...@@ -1667,6 +1578,102 @@ async function example() {
} }
``` ```
### on
on(type: ChangeEvent, callback: Callback&lt;void&gt;): void
Subscribes to changes of the file management library. This API uses a callback to return the result.
This API will be deprecated. Use [on<sup>10+</sup>](#on10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.<br>**deviceChange** indicates the device change.<br>**albumChange** indicates the album change.<br>**imageChange** indicates the image change.<br>**audioChange** indicates the audio file change.<br>**videoChange** indicates the video file change.<br>**remoteFileChange** indicates the file change on the registered device.|
| callback | Callback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```ts
async function example() {
console.info('onDemo');
let count = 0;
mgr.on('imageChange', () => {
count++;
// Image file changed. Do something.
});
try {
let testFileName = 'testFile' + Date.now() + '.jpg';
let fileAsset = await mgr.createPhotoAsset(testFileName);
console.info('createPhotoAsset file displayName' + fileAsset.displayName);
console.info('createPhotoAsset successfully');
} catch (err) {
console.error('createPhotoAsset failed, message = ' + err);
}
// Sleep 1s.
if (count > 0) {
console.info('onDemo success');
} else {
console.error('onDemo fail');
}
mgr.off('imageChange', () => {
// Unsubscription succeeds.
});
}
```
### off
off(type: ChangeEvent, callback?: Callback&lt;void&gt;): void
Unsubscribes from changes of the file management library. This API uses a callback to return the result.
This API will be deprecated. Use [off<sup>10+</sup>](#off10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.<br>**deviceChange** indicates the device change.<br>**albumChange** indicates the album change.<br>**imageChange** indicates the image change.<br>**audioChange** indicates the audio file change.<br>**videoChange** indicates the video file change.<br>**remoteFileChange** indicates the change of the file on a registered device.|
| callback | Callback&lt;void&gt; | No | Callback that returns no value. |
**Example**
```ts
async function example() {
console.info('offDemo');
let count = 0;
mgr.on('imageChange', () => {
count++;
// Image file changed. Do something.
});
mgr.off('imageChange', () => {
// Unsubscription succeeds.
});
try {
let testFileName = 'testFile' + Date.now() + '.jpg';
let fileAsset = await mgr.createPhotoAsset(testFileName);
console.info('createPhotoAsset file displayName' + fileAsset.displayName);
console.info('createPhotoAsset successfully');
} catch (err) {
console.error('createPhotoAsset failed, message = ' + err);
}
// Sleep 1s.
if (count == 0) {
console.info('offDemo success');
} else {
console.error('offDemo fail');
}
}
```
## FileAsset ## FileAsset
Provides APIs for encapsulating file asset attributes. Provides APIs for encapsulating file asset attributes.
...@@ -1818,7 +1825,7 @@ Commits the modification on the file metadata to the database. This API uses a p ...@@ -1818,7 +1825,7 @@ Commits the modification on the file metadata to the database. This API uses a p
| ------------------- | ---------- | | ------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```ts ```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
...@@ -3488,6 +3495,8 @@ async function example() { ...@@ -3488,6 +3495,8 @@ async function example() {
Provides APIs for managing the system albums. Provides APIs for managing the system albums.
This API will be discarded. Use [Album](#album) instead.
### Attributes ### Attributes
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3506,6 +3515,8 @@ getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt; ...@@ -3506,6 +3515,8 @@ getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;
Obtains image and video assets from a system album. This API uses an asynchronous callback to return the result. Obtains image and video assets from a system album. This API uses an asynchronous callback to return the result.
This API will be deprecated. Use [Album.getPhotoAssets](#getphotoassets-2) instead.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO **Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3557,6 +3568,8 @@ getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&g ...@@ -3557,6 +3568,8 @@ getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&g
Obtains image and video assets from a system album. This API uses a promise to return the result. Obtains image and video assets from a system album. This API uses a promise to return the result.
This API will be deprecated. Use [Album.getPhotoAssets](#getphotoassets-3) instead.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO **Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3607,6 +3620,8 @@ delete(uri: string, callback: AsyncCallback&lt;void&gt;): void; ...@@ -3607,6 +3620,8 @@ delete(uri: string, callback: AsyncCallback&lt;void&gt;): void;
Deletes files from a system album. Deletes files from a system album.
This API will be deprecated. Use [Album.deletePhotoAssets](#deletephotoassets10) instead.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO **Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3651,6 +3666,8 @@ delete(uri: string): Promise&lt;void&gt;; ...@@ -3651,6 +3666,8 @@ delete(uri: string): Promise&lt;void&gt;;
Deletes files from a system album. Deletes files from a system album.
This API will be deprecated. Use [Album.deletePhotoAssets](#deletephotoassets10) instead.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO **Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3689,7 +3706,7 @@ async function example() { ...@@ -3689,7 +3706,7 @@ async function example() {
}).catch((err) => { }).catch((err) => {
console.error('trashAlbum.delete failed, message = ', err); console.error('trashAlbum.delete failed, message = ', err);
}); });
} }
``` ```
### recover ### recover
...@@ -3698,6 +3715,8 @@ recover(uri: string, callback: AsyncCallback&lt;void&gt;): void; ...@@ -3698,6 +3715,8 @@ recover(uri: string, callback: AsyncCallback&lt;void&gt;): void;
Recovers files in a system album. Recovers files in a system album.
This API will be deprecated. Use [Album.recoverPhotoAssets](#recoverphotoassets10) instead.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO **Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3742,6 +3761,8 @@ recover(uri: string): Promise&lt;void&gt;; ...@@ -3742,6 +3761,8 @@ recover(uri: string): Promise&lt;void&gt;;
Recovers files in a system album. Recovers files in a system album.
This API will be deprecated. Use [Album.recoverPhotoAssets](#recoverphotoassets10) instead.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO **Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
...@@ -3890,6 +3911,8 @@ Enumerate the album subtypes. ...@@ -3890,6 +3911,8 @@ Enumerate the album subtypes.
Enumerates the system album types. Enumerates the system album types.
This API will be deprecated. Use [AlbumType](#albumtype10) and [AlbumSubType](#albumsubtype10) instead.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core **System capability**: SystemCapability.FileManagement.UserFileManager.Core
| Name | Value| Description | | Name | Value| Description |
...@@ -3938,6 +3961,7 @@ Defines the key information about an image or video file. ...@@ -3938,6 +3961,7 @@ Defines the key information about an image or video file.
| POSITION<sup>10+</sup> | position | File location type. | | POSITION<sup>10+</sup> | position | File location type. |
| DATE_TRASHED<sup>10+</sup> | date_trashed | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. | | DATE_TRASHED<sup>10+</sup> | date_trashed | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. |
| HIDDEN<sup>10+</sup> | hidden | Whether the file is hidden. | | HIDDEN<sup>10+</sup> | hidden | Whether the file is hidden. |
| CAMERA_SHOT_KEY<sup>10+</sup> | camera_shot_key | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) |
## AlbumKey ## AlbumKey
...@@ -3962,6 +3986,7 @@ Options for creating an image or video asset. ...@@ -3962,6 +3986,7 @@ Options for creating an image or video asset.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ | | ---------------------- | ------------------- | ---- | ------------------------------------------------ |
| subType | [PhotoSubType](#photosubtype10) | No | Subtype of the image or video. | | subType | [PhotoSubType](#photosubtype10) | No | Subtype of the image or video. |
| cameraShotKey | string | No | Key for the Untra Snamshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) |
## FetchOptions ## FetchOptions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册