提交 bef08fae 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 85afa50c
...@@ -185,7 +185,7 @@ function getListFile() { ...@@ -185,7 +185,7 @@ function getListFile() {
public filter: Filter public filter: Filter
} }
let option = new ListFileOption(); let option = new ListFileOption();
option.filter.suffix = ['.png', '.jpg', '.txt']; // The filen ame extension can be '.png', '.jpg', or '.txt'. option.filter.suffix = ['.png', '.jpg', '.txt']; // The file name extension can be '.png', '.jpg', or '.txt'.
option.filter.displayName = ['test%']; // The file name starts with 'test'. option.filter.displayName = ['test%']; // The file name starts with 'test'.
option.filter.fileSizeOver = 0; // The file size is greater than or equal to 0. option.filter.fileSizeOver = 0; // The file size is greater than or equal to 0.
option.filter.lastModifiedAfter = new Date(0).getTime(); // The latest modification time of the file is later than January 1, 1970. option.filter.lastModifiedAfter = new Date(0).getTime(); // The latest modification time of the file is later than January 1, 1970.
......
...@@ -8,8 +8,13 @@ ...@@ -8,8 +8,13 @@
## Modules to Import ## Modules to Import
```js > **NOTE**
>
> You need to import the **BusinessError** module if **BusinessError** is used in the sample code.
```ts
import picker from '@ohos.file.picker'; import picker from '@ohos.file.picker';
import { BusinessError } from '@ohos.base';
``` ```
## PhotoViewPicker ## PhotoViewPicker
...@@ -47,19 +52,20 @@ Selects one or more images or videos in a **photoPicker** page. This API uses a ...@@ -47,19 +52,20 @@ Selects one or more images or videos in a **photoPicker** page. This API uses a
**Example** **Example**
```ts ```ts
async function example() { async function example01() {
try { try {
let PhotoSelectOptions = new picker.PhotoSelectOptions(); let PhotoSelectOptions = new picker.PhotoSelectOptions();
PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
PhotoSelectOptions.maxSelectNumber = 5; PhotoSelectOptions.maxSelectNumber = 5;
let photoPicker = new picker.PhotoViewPicker(); let photoPicker = new picker.PhotoViewPicker();
photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => {
console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('PhotoViewPicker.select failed with err: ' + err); console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (error) {
console.error('PhotoViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -82,21 +88,22 @@ Selects one or more images or videos in a **photoPicker** page. This API uses an ...@@ -82,21 +88,22 @@ Selects one or more images or videos in a **photoPicker** page. This API uses an
**Example** **Example**
```ts ```ts
async function example() { async function example02() {
try { try {
let PhotoSelectOptions = new picker.PhotoSelectOptions(); let PhotoSelectOptions = new picker.PhotoSelectOptions();
PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
PhotoSelectOptions.maxSelectNumber = 5; PhotoSelectOptions.maxSelectNumber = 5;
let photoPicker = new picker.PhotoViewPicker(); let photoPicker = new picker.PhotoViewPicker();
photoPicker.select(PhotoSelectOptions, (err, PhotoSelectResult) => { photoPicker.select(PhotoSelectOptions, (err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => {
if (err) { if (err) {
console.error('PhotoViewPicker.select failed with err: ' + err); console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
}); });
} catch (err) { } catch (error) {
console.error('PhotoViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -118,18 +125,19 @@ Selects one or more images or videos in a **photoPicker** page. This API uses an ...@@ -118,18 +125,19 @@ Selects one or more images or videos in a **photoPicker** page. This API uses an
**Example** **Example**
```ts ```ts
async function example() { async function example03() {
try { try {
let photoPicker = new picker.PhotoViewPicker(); let photoPicker = new picker.PhotoViewPicker();
photoPicker.select((err, PhotoSelectResult) => { photoPicker.select((err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => {
if (err) { if (err) {
console.error('PhotoViewPicker.select failed with err: ' + err); console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
}); });
} catch (err) { } catch (error) {
console.error('PhotoViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -138,7 +146,7 @@ async function example() { ...@@ -138,7 +146,7 @@ async function example() {
save(option?: PhotoSaveOptions) : Promise&lt;Array&lt;string&gt;&gt; save(option?: PhotoSaveOptions) : Promise&lt;Array&lt;string&gt;&gt;
Saves one or more images or videos in a **photoPicker** page. This API uses a promise to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves the file in the file manager, not in the Gallery. Saves one or more images or videos in a **photoPicker** page. This API uses a promise to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves files in the file manager, not in **Gallery**.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -157,18 +165,19 @@ Saves one or more images or videos in a **photoPicker** page. This API uses a pr ...@@ -157,18 +165,19 @@ Saves one or more images or videos in a **photoPicker** page. This API uses a pr
**Example** **Example**
```ts ```ts
async function example() { async function example04() {
try { try {
let PhotoSaveOptions = new picker.PhotoSaveOptions(); let PhotoSaveOptions = new picker.PhotoSaveOptions();
PhotoSaveOptions.newFileNames = ['PhotoViewPicker01.jpg', 'PhotoViewPicker01.mp4']; PhotoSaveOptions.newFileNames = ['PhotoViewPicker01.jpg', 'PhotoViewPicker01.mp4'];
let photoPicker = new picker.PhotoViewPicker(); let photoPicker = new picker.PhotoViewPicker();
photoPicker.save(PhotoSaveOptions).then((PhotoSaveResult) => { photoPicker.save(PhotoSaveOptions).then((PhotoSaveResult: Array<string>) => {
console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('PhotoViewPicker.save failed with err: ' + err); console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (error) {
console.error('PhotoViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -177,7 +186,7 @@ async function example() { ...@@ -177,7 +186,7 @@ async function example() {
save(option: PhotoSaveOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void save(option: PhotoSaveOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void
Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves the file in the file manager, not in the Gallery. Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves files in the file manager, not in **Gallery**.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -191,20 +200,21 @@ Saves one or more images or videos in a **photoPicker** page. This API uses an a ...@@ -191,20 +200,21 @@ Saves one or more images or videos in a **photoPicker** page. This API uses an a
**Example** **Example**
```ts ```ts
async function example() { async function example05() {
try { try {
let PhotoSaveOptions = new picker.PhotoSaveOptions(); let PhotoSaveOptions = new picker.PhotoSaveOptions();
PhotoSaveOptions.newFileNames = ['PhotoViewPicker02.jpg','PhotoViewPicker02.mp4']; PhotoSaveOptions.newFileNames = ['PhotoViewPicker02.jpg','PhotoViewPicker02.mp4'];
let photoPicker = new picker.PhotoViewPicker(); let photoPicker = new picker.PhotoViewPicker();
photoPicker.save(PhotoSaveOptions, (err, PhotoSaveResult) => { photoPicker.save(PhotoSaveOptions, (err: BusinessError, PhotoSaveResult: Array<string>) => {
if (err) { if (err) {
console.error('PhotoViewPicker.save failed with err: ' + err); console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult));
}); });
} catch (err) { } catch (error) {
console.error('PhotoViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -213,7 +223,7 @@ async function example() { ...@@ -213,7 +223,7 @@ async function example() {
save(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void save(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void
Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. The **save()** API saves the file in the file manager, not in the Gallery. Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. The **save()** API saves files in the file manager, not in **Gallery**.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -226,25 +236,26 @@ Saves one or more images or videos in a **photoPicker** page. This API uses an a ...@@ -226,25 +236,26 @@ Saves one or more images or videos in a **photoPicker** page. This API uses an a
**Example** **Example**
```ts ```ts
async function example() { async function example06() {
try { try {
let photoPicker = new picker.PhotoViewPicker(); let photoPicker = new picker.PhotoViewPicker();
photoPicker.save((err, PhotoSaveResult) => { photoPicker.save((err: BusinessError, PhotoSaveResult: Array<string>) => {
if (err) { if (err) {
console.error('PhotoViewPicker.save failed with err: ' + err); console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult));
}); });
} catch (err) { } catch (error) {
console.error('PhotoViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
## DocumentViewPicker ## DocumentViewPicker
Provides APIs for selecting and saving non-media files, for example, documents in a variety of formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance. Provides the **DocumentViewPicker** object for selecting and saving documents in different formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -277,17 +288,18 @@ Selects one or more documents in a **documentPicker** page. This API uses a prom ...@@ -277,17 +288,18 @@ Selects one or more documents in a **documentPicker** page. This API uses a prom
**Example** **Example**
```ts ```ts
async function example() { async function example07() {
try { try {
let DocumentSelectOptions = new picker.DocumentSelectOptions(); let DocumentSelectOptions = new picker.DocumentSelectOptions();
let documentPicker = new picker.DocumentViewPicker(); let documentPicker = new picker.DocumentViewPicker();
documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => { documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult: Array<string>) => {
console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('DocumentViewPicker.select failed with err: ' + err); console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (error) {
console.error('DocumentViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -310,19 +322,20 @@ Selects one or more documents in a **documentPicker** page. This API uses an asy ...@@ -310,19 +322,20 @@ Selects one or more documents in a **documentPicker** page. This API uses an asy
**Example** **Example**
```ts ```ts
async function example() { async function example08() {
try { try {
let DocumentSelectOptions = new picker.DocumentSelectOptions(); let DocumentSelectOptions = new picker.DocumentSelectOptions();
let documentPicker = new picker.DocumentViewPicker(); let documentPicker = new picker.DocumentViewPicker();
documentPicker.select(DocumentSelectOptions, (err, DocumentSelectResult) => { documentPicker.select(DocumentSelectOptions, (err: BusinessError, DocumentSelectResult: Array<string>) => {
if (err) { if (err) {
console.error('DocumentViewPicker.select failed with err: ' + err); console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
}); });
} catch (err) { } catch (error) {
console.error('DocumentViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -344,18 +357,19 @@ Selects one or more documents in a **documentPicker** page. This API uses an asy ...@@ -344,18 +357,19 @@ Selects one or more documents in a **documentPicker** page. This API uses an asy
**Example** **Example**
```ts ```ts
async function example() { async function example09() {
try { try {
let documentPicker = new picker.DocumentViewPicker(); let documentPicker = new picker.DocumentViewPicker();
documentPicker.select((err, DocumentSelectResult) => { documentPicker.select((err: BusinessError, DocumentSelectResult: Array<string>) => {
if (err) { if (err) {
console.error('DocumentViewPicker.select failed with err: ' + err); console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
}); });
} catch (err) { } catch (error) {
console.error('DocumentViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -384,18 +398,19 @@ Saves one or more documents in a **documentPicker** page. This API uses a promis ...@@ -384,18 +398,19 @@ Saves one or more documents in a **documentPicker** page. This API uses a promis
**Example** **Example**
```ts ```ts
async function example() { async function example10() {
try { try {
let DocumentSaveOptions = new picker.DocumentSaveOptions(); let DocumentSaveOptions = new picker.DocumentSaveOptions();
DocumentSaveOptions.newFileNames = ['DocumentViewPicker01.txt']; DocumentSaveOptions.newFileNames = ['DocumentViewPicker01.txt'];
let documentPicker = new picker.DocumentViewPicker(); let documentPicker = new picker.DocumentViewPicker();
documentPicker.save(DocumentSaveOptions).then((DocumentSaveResult) => { documentPicker.save(DocumentSaveOptions).then((DocumentSaveResult: Array<string>) => {
console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('DocumentViewPicker.save failed with err: ' + err); console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (error) {
console.error('DocumentViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -418,20 +433,21 @@ Saves one or more documents in a **documentPicker** page. This API uses an async ...@@ -418,20 +433,21 @@ Saves one or more documents in a **documentPicker** page. This API uses an async
**Example** **Example**
```ts ```ts
async function example() { async function example11() {
try { try {
let DocumentSaveOptions = new picker.DocumentSaveOptions(); let DocumentSaveOptions = new picker.DocumentSaveOptions();
DocumentSaveOptions.newFileNames = ['DocumentViewPicker02.txt']; DocumentSaveOptions.newFileNames = ['DocumentViewPicker02.txt'];
let documentPicker = new picker.DocumentViewPicker(); let documentPicker = new picker.DocumentViewPicker();
documentPicker.save(DocumentSaveOptions, (err, DocumentSaveResult) => { documentPicker.save(DocumentSaveOptions, (err: BusinessError, DocumentSaveResult: Array<string>) => {
if (err) { if (err) {
console.error('DocumentViewPicker.save failed with err: ' + err); console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult));
}); });
} catch (err) { } catch (error) {
console.error('DocumentViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -453,18 +469,19 @@ Saves one or more documents in a **documentPicker** page. This API uses an async ...@@ -453,18 +469,19 @@ Saves one or more documents in a **documentPicker** page. This API uses an async
**Example** **Example**
```ts ```ts
async function example() { async function example12() {
try { try {
let documentPicker = new picker.DocumentViewPicker(); let documentPicker = new picker.DocumentViewPicker();
documentPicker.save((err, DocumentSaveResult) => { documentPicker.save((err: BusinessError, DocumentSaveResult: Array<string>) => {
if (err) { if (err) {
console.error('DocumentViewPicker.save failed with err: ' + err); console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult));
}); });
} catch (err) { } catch (error) {
console.error('DocumentViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -504,17 +521,18 @@ Selects one or more audio files in an **audioPicker** page (currently, a **docum ...@@ -504,17 +521,18 @@ Selects one or more audio files in an **audioPicker** page (currently, a **docum
**Example** **Example**
```ts ```ts
async function example() { async function example13() {
try { try {
let AudioSelectOptions = new picker.AudioSelectOptions(); let AudioSelectOptions = new picker.AudioSelectOptions();
let audioPicker = new picker.AudioViewPicker(); let audioPicker = new picker.AudioViewPicker();
audioPicker.select(AudioSelectOptions).then((AudioSelectResult) => { audioPicker.select(AudioSelectOptions).then((AudioSelectResult: Array<string>) => {
console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult));
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('AudioViewPicker.select failed with err: ' + err); console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (error) {
console.error('AudioViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -537,19 +555,20 @@ Selects one or more audio files in an **audioPicker** page (currently, a **docum ...@@ -537,19 +555,20 @@ Selects one or more audio files in an **audioPicker** page (currently, a **docum
**Example** **Example**
```ts ```ts
async function example() { async function example14() {
try { try {
let AudioSelectOptions = new picker.AudioSelectOptions(); let AudioSelectOptions = new picker.AudioSelectOptions();
let audioPicker = new picker.AudioViewPicker(); let audioPicker = new picker.AudioViewPicker();
audioPicker.select(AudioSelectOptions, (err, AudioSelectResult) => { audioPicker.select(AudioSelectOptions, (err: BusinessError, AudioSelectResult: Array<string>) => {
if (err) { if (err) {
console.error('AudioViewPicker.select failed with err: ' + err); console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult));
}); });
} catch (err) { } catch (error) {
console.error('AudioViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -571,18 +590,19 @@ Selects one or more audio files in an **audioPicker** page (currently, a **docum ...@@ -571,18 +590,19 @@ Selects one or more audio files in an **audioPicker** page (currently, a **docum
**Example** **Example**
```ts ```ts
async function example() { async function example15() {
try { try {
let audioPicker = new picker.AudioViewPicker(); let audioPicker = new picker.AudioViewPicker();
audioPicker.select((err, AudioSelectResult) => { audioPicker.select((err: BusinessError, AudioSelectResult: Array<string>) => {
if (err) { if (err) {
console.error('AudioViewPicker.select failed with err: ' + err); console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult));
}); });
} catch (err) { } catch (error) {
console.error('AudioViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -610,18 +630,19 @@ Saves one or more audio files in an **audioPicker** page (currently, a **documen ...@@ -610,18 +630,19 @@ Saves one or more audio files in an **audioPicker** page (currently, a **documen
**Example** **Example**
```ts ```ts
async function example() { async function example16() {
try { try {
let AudioSaveOptions = new picker.AudioSaveOptions(); let AudioSaveOptions = new picker.AudioSaveOptions();
AudioSaveOptions.newFileNames = ['AudioViewPicker01.mp3']; AudioSaveOptions.newFileNames = ['AudioViewPicker01.mp3'];
let audioPicker = new picker.AudioViewPicker(); let audioPicker = new picker.AudioViewPicker();
audioPicker.save(AudioSaveOptions).then((AudioSaveResult) => { audioPicker.save(AudioSaveOptions).then((AudioSaveResult: Array<string>) => {
console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)) console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult))
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('AudioViewPicker.save failed with err: ' + err); console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err));
}); });
} catch (err) { } catch (error) {
console.error('AudioViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -644,20 +665,21 @@ Saves one or more audio files in an **audioPicker** page (currently, a **documen ...@@ -644,20 +665,21 @@ Saves one or more audio files in an **audioPicker** page (currently, a **documen
**Example** **Example**
```ts ```ts
async function example() { async function example17() {
try { try {
let AudioSaveOptions = new picker.AudioSaveOptions(); let AudioSaveOptions = new picker.AudioSaveOptions();
AudioSaveOptions.newFileNames = ['AudioViewPicker02.mp3']; AudioSaveOptions.newFileNames = ['AudioViewPicker02.mp3'];
let audioPicker = new picker.AudioViewPicker(); let audioPicker = new picker.AudioViewPicker();
audioPicker.save(AudioSaveOptions, (err, AudioSaveResult) => { audioPicker.save(AudioSaveOptions, (err: BusinessError, AudioSaveResult: Array<string>) => {
if (err) { if (err) {
console.error('AudioViewPicker.save failed with err: ' + err); console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)); console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult));
}); });
} catch (err) { } catch (error) {
console.error('AudioViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -679,18 +701,19 @@ Saves one or more audio files in an **audioPicker** page (currently, a **documen ...@@ -679,18 +701,19 @@ Saves one or more audio files in an **audioPicker** page (currently, a **documen
**Example** **Example**
```ts ```ts
async function example() { async function example18() {
try { try {
let audioPicker = new picker.AudioViewPicker(); let audioPicker = new picker.AudioViewPicker();
audioPicker.save((err, AudioSaveResult) => { audioPicker.save((err: BusinessError, AudioSaveResult: Array<string>) => {
if (err) { if (err) {
console.error('AudioViewPicker.save failed with err: ' + err); console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err));
return; return;
} }
console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)); console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult));
}); });
} catch (err) { } catch (error) {
console.error('AudioViewPicker failed with err: ' + err); let err: BusinessError = error as BusinessError;
console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
} }
} }
``` ```
...@@ -715,8 +738,8 @@ Defines the options for selecting images or videos. ...@@ -715,8 +738,8 @@ Defines the options for selecting images or videos.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | -------------------------------- | | ----------------------- | ------------------- | ---- | -------------------------------- |
| MIMEType? | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Available media file types. **IMAGE_VIDEO_TYPE** is used by default.| | MIMEType | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Available media file types. **IMAGE_VIDEO_TYPE** is used by default.|
| maxSelectNumber? | number | No | Maximum number of media files to select. The default value is **50**, and the maximum value is **500**. | | maxSelectNumber | number | No | Maximum number of media files to select. The default value is **50**, and the maximum value is **500**. |
## PhotoSelectResult ## PhotoSelectResult
...@@ -737,14 +760,20 @@ Defines the options for saving images or videos. ...@@ -737,14 +760,20 @@ Defines the options for saving images or videos.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ---------------------------- | | ----------------------- | ------------------- | ---- | ---------------------------- |
| newFileNames? | Array&lt;string&gt; | No | Names of the files to save. If this parameter is not specified, the user needs to enter the file names.| | newFileNames | Array&lt;string&gt; | No | Names of the files to save. If this parameter is not specified, the user needs to enter the file names.|
## DocumentSelectOptions ## DocumentSelectOptions
Defines the options for selecting documents. Currently, this parameter cannot be configured. Defines the options for selecting documents.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | -------------------------------- |
| maxSelectNumber<sup>10+</sup> | number | No | Maximum number of files or directories that can be selected.<br>Value range: 1–500<br>Maximum value: **500** |
| defaultFilePathUri<sup>10+</sup> | string | No | Path of the file or directory to select.|
| fileSuffixFilters<sup>10+</sup> | Array&lt;string&gt; | No | File name extensions of the documents to select.|
## DocumentSaveOptions ## DocumentSaveOptions
Defines the options for saving documents. Defines the options for saving documents.
...@@ -753,7 +782,9 @@ Defines the options for saving documents. ...@@ -753,7 +782,9 @@ Defines the options for saving documents.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ---------------------------- | | ----------------------- | ------------------- | ---- | ---------------------------- |
| newFileNames? | Array&lt;string&gt; | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. | | newFileNames | Array&lt;string&gt; | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. |
| defaultFilePathUri<sup>10+</sup> | string | No | Path of the file or directory to save.|
| fileSuffixChoices<sup>10+</sup> | Array&lt;string&gt; | No | File name extensions of the documents to save.|
## AudioSelectOptions ## AudioSelectOptions
...@@ -769,4 +800,4 @@ Defines the options for saving audio files. ...@@ -769,4 +800,4 @@ Defines the options for saving audio files.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ---------------------------- | | ----------------------- | ------------------- | ---- | ---------------------------- |
| newFileNames? | Array&lt;string&gt; | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.| | newFileNames | Array&lt;string&gt; | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册