提交 bdf87f7d 编写于 作者: W wangdongqi

Signed-off-by: wangdongqi <wangdongqi2@huawei.com>

 Changes to be committed:

 Changes to be committed:

 Changes to be committed:

 Changes to be committed:

 Changes to be committed:

 Changes to be committed:

 Changes to be committed:
上级 1bf58a6e
...@@ -705,7 +705,7 @@ try { ...@@ -705,7 +705,7 @@ try {
attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt; attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt;
用于自绘控件绑定输入法应用。使用callback异步回调。 用于自绘控件绑定输入法应用。使用promise异步回调。
必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。 必须先调用此接口完成自绘控件与输入法应用的绑定,才可以使用输入法框架的以下功能:显示、隐藏键盘;更新光标信息;更改编辑框选中范围;保存配置信息;监听处理由输入法应用发送的信息或命令等。
......
...@@ -105,6 +105,7 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt ...@@ -105,6 +105,7 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt
```js ```js
let uploadTask; let uploadTask;
let context;
let uploadConfig = { let uploadConfig = {
url: 'http://patch', url: 'http://patch',
header: { key1: "value1", key2: "value2" }, header: { key1: "value1", key2: "value2" },
...@@ -113,16 +114,20 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt ...@@ -113,16 +114,20 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt
data: [{ name: "name123", value: "123" }], data: [{ name: "name123", value: "123" }],
}; };
try { try {
request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => { request.uploadFile(context, uploadConfig).then((data) => {
uploadTask = data; uploadTask = data;
}).catch((err) => { }).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
}); });
} catch (err) { } catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
} }
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
## request.uploadFile<sup>9+</sup> ## request.uploadFile<sup>9+</sup>
...@@ -154,6 +159,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l ...@@ -154,6 +159,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l
```js ```js
let uploadTask; let uploadTask;
let context;
let uploadConfig = { let uploadConfig = {
url: 'http://patch', url: 'http://patch',
header: { key1: "value1", key2: "value2" }, header: { key1: "value1", key2: "value2" },
...@@ -162,18 +168,22 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l ...@@ -162,18 +168,22 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l
data: [{ name: "name123", value: "123" }], data: [{ name: "name123", value: "123" }],
}; };
try { try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { request.uploadFile(context, uploadConfig, (err, data) => {
if (err) { if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
uploadTask = data; uploadTask = data;
}); });
} catch (err) { } catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
} }
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
## request.upload<sup>(deprecated)</sup> ## request.upload<sup>(deprecated)</sup>
upload(config: UploadConfig): Promise&lt;UploadTask&gt; upload(config: UploadConfig): Promise&lt;UploadTask&gt;
...@@ -214,7 +224,7 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt; ...@@ -214,7 +224,7 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt;
request.upload(uploadConfig).then((data) => { request.upload(uploadConfig).then((data) => {
uploadTask = data; uploadTask = data;
}).catch((err) => { }).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -253,7 +263,7 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void ...@@ -253,7 +263,7 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
}; };
request.upload(uploadConfig, (err, data) => { request.upload(uploadConfig, (err, data) => {
if (err) { if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
uploadTask = data; uploadTask = data;
...@@ -485,12 +495,12 @@ delete(): Promise&lt;boolean&gt; ...@@ -485,12 +495,12 @@ delete(): Promise&lt;boolean&gt;
```js ```js
uploadTask.delete().then((result) => { uploadTask.delete().then((result) => {
if (result) { if (result) {
console.info('Upload task removed successfully. '); console.info('Succeeded in deleting the upload task.');
} else { } else {
console.error('Failed to remove the upload task. '); console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`);
} }
}).catch((err) => { }).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -516,13 +526,13 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -516,13 +526,13 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void
```js ```js
uploadTask.delete((err, result) => { uploadTask.delete((err, result) => {
if (err) { if (err) {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Upload task removed successfully.'); console.info('Succeeded in deleting the upload task.');
} else { } else {
console.error('Failed to remove the upload task.'); console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -551,12 +561,12 @@ remove(): Promise&lt;boolean&gt; ...@@ -551,12 +561,12 @@ remove(): Promise&lt;boolean&gt;
```js ```js
uploadTask.remove().then((result) => { uploadTask.remove().then((result) => {
if (result) { if (result) {
console.info('Upload task removed successfully. '); console.info('Succeeded in removing the upload task.');
} else { } else {
console.error('Failed to remove the upload task. '); console.error(`Failed to remove the upload task. Code: ${err.code}, message: ${err.message}`);
} }
}).catch((err) => { }).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); console.error(`Failed to remove the upload task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -584,13 +594,13 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -584,13 +594,13 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void
```js ```js
uploadTask.remove((err, result) => { uploadTask.remove((err, result) => {
if (err) { if (err) {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); console.error(`Failed to remove the upload task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Upload task removed successfully.'); console.info('Succeeded in removing the upload task.');
} else { } else {
console.error('Failed to remove the upload task.'); console.error(`Failed to remove the upload task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -688,17 +698,22 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadT ...@@ -688,17 +698,22 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadT
```js ```js
let downloadTask; let downloadTask;
let context;
try { try {
request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => { request.downloadFile(context, { url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data; downloadTask = data;
}).catch((err) => { }).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
}) })
} catch (err) { } catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
} }
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
## request.downloadFile<sup>9+</sup> ## request.downloadFile<sup>9+</sup>
...@@ -733,20 +748,25 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba ...@@ -733,20 +748,25 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba
```js ```js
let downloadTask; let downloadTask;
let context;
try { try {
request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap', request.downloadFile(context, { url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => { filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) { if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
downloadTask = data; downloadTask = data;
}); });
} catch (err) { } catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
} }
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
## request.download<sup>(deprecated)</sup> ## request.download<sup>(deprecated)</sup>
download(config: DownloadConfig): Promise&lt;DownloadTask&gt; download(config: DownloadConfig): Promise&lt;DownloadTask&gt;
...@@ -780,7 +800,7 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt; ...@@ -780,7 +800,7 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt;
request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => { request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data; downloadTask = data;
}).catch((err) => { }).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -813,7 +833,7 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v ...@@ -813,7 +833,7 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v
request.download({ url: 'https://xxxx/xxxxx.hap', request.download({ url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => { filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) { if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
downloadTask = data; downloadTask = data;
...@@ -987,7 +1007,7 @@ on(type: 'fail', callback: (err: number) =&gt; void): void ...@@ -987,7 +1007,7 @@ on(type: 'fail', callback: (err: number) =&gt; void): void
```js ```js
let failCallback = (err) => { let failCallback = (err) => {
console.info('Download task failed. Cause:' + err); console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`);
}; };
downloadTask.on('fail', failCallback); downloadTask.on('fail', failCallback);
``` ```
...@@ -1014,7 +1034,7 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void ...@@ -1014,7 +1034,7 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void
```js ```js
let failCallback = (err) => { let failCallback = (err) => {
console.info(`Download delete fail notification. err: ${err.message}`); console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`);
}; };
downloadTask.off('fail', failCallback); downloadTask.off('fail', failCallback);
``` ```
...@@ -1040,12 +1060,12 @@ delete(): Promise&lt;boolean&gt; ...@@ -1040,12 +1060,12 @@ delete(): Promise&lt;boolean&gt;
```js ```js
downloadTask.delete().then((result) => { downloadTask.delete().then((result) => {
if (result) { if (result) {
console.info('Download task removed.'); console.info('Succeeded in removing the download task.');
} else { } else {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
} }
}).catch ((err) => { }).catch ((err) => {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1071,13 +1091,13 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1071,13 +1091,13 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void
```js ```js
downloadTask.delete((err, result)=>{ downloadTask.delete((err, result)=>{
if(err) { if(err) {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Download task removed.'); console.info('Succeeded in removing the download task.');
} else { } else {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -1103,9 +1123,9 @@ getTaskInfo(): Promise&lt;DownloadInfo&gt; ...@@ -1103,9 +1123,9 @@ getTaskInfo(): Promise&lt;DownloadInfo&gt;
```js ```js
downloadTask.getTaskInfo().then((downloadInfo) => { downloadTask.getTaskInfo().then((downloadInfo) => {
console.info('Download task queried. Data:' + JSON.stringify(downloadInfo)) console.info('Succeeded in querying the download task')
}) .catch((err) => { }) .catch((err) => {
console.error('Failed to query the download task. Cause:' + err) console.error(`Failed to query the download task. Code: ${err.code}, message: ${err.message}`)
}); });
``` ```
...@@ -1131,9 +1151,9 @@ getTaskInfo(callback: AsyncCallback&lt;DownloadInfo&gt;): void ...@@ -1131,9 +1151,9 @@ getTaskInfo(callback: AsyncCallback&lt;DownloadInfo&gt;): void
```js ```js
downloadTask.getTaskInfo((err, downloadInfo)=>{ downloadTask.getTaskInfo((err, downloadInfo)=>{
if(err) { if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err)); console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info('download query success. data:'+ JSON.stringify(downloadInfo)); console.info('Succeeded in querying the download mimeType');
} }
}); });
``` ```
...@@ -1159,9 +1179,9 @@ getTaskMimeType(): Promise&lt;string&gt; ...@@ -1159,9 +1179,9 @@ getTaskMimeType(): Promise&lt;string&gt;
```js ```js
downloadTask.getTaskMimeType().then((data) => { downloadTask.getTaskMimeType().then((data) => {
console.info('Download task queried. Data:' + JSON.stringify(data)); console.info('Succeeded in querying the download MimeType');
}).catch((err) => { }).catch((err) => {
console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err)) console.error(`Failed to query the download MimeType. Code: ${err.code}, message: ${err.message}`)
}); });
``` ```
...@@ -1187,9 +1207,9 @@ getTaskMimeType(callback: AsyncCallback&lt;string&gt;): void; ...@@ -1187,9 +1207,9 @@ getTaskMimeType(callback: AsyncCallback&lt;string&gt;): void;
```js ```js
downloadTask.getTaskMimeType((err, data)=>{ downloadTask.getTaskMimeType((err, data)=>{
if(err) { if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err)); console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info('Download task queried. data:' + JSON.stringify(data)); console.info('Succeeded in querying the download mimeType');
} }
}); });
``` ```
...@@ -1216,12 +1236,12 @@ suspend(): Promise&lt;boolean&gt; ...@@ -1216,12 +1236,12 @@ suspend(): Promise&lt;boolean&gt;
```js ```js
downloadTask.suspend().then((result) => { downloadTask.suspend().then((result) => {
if (result) { if (result) {
console.info('Download task paused. '); console.info('Succeeded in pausing the download task.');
} else { } else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
} }
}).catch((err) => { }).catch((err) => {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1247,13 +1267,13 @@ suspend(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1247,13 +1267,13 @@ suspend(callback: AsyncCallback&lt;boolean&gt;): void
```js ```js
downloadTask.suspend((err, result)=>{ downloadTask.suspend((err, result)=>{
if(err) { if(err) {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Download task paused. '); console.info('Succeeded in pausing the download task.');
} else { } else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -1280,13 +1300,13 @@ restore(): Promise&lt;boolean&gt; ...@@ -1280,13 +1300,13 @@ restore(): Promise&lt;boolean&gt;
```js ```js
downloadTask.restore().then((result) => { downloadTask.restore().then((result) => {
if (result) { if (result) {
console.info('Download task resumed.') console.info('Succeeded in resuming the download task.')
} else { } else {
console.error('Failed to resume the download task. '); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
} }
console.info('Download task resumed.') console.info('Succeeded in resuming the download task.')
}).catch((err) => { }).catch((err) => {
console.error('Failed to resume the download task. Cause:' + err); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1312,19 +1332,18 @@ restore(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1312,19 +1332,18 @@ restore(callback: AsyncCallback&lt;boolean&gt;): void
```js ```js
downloadTask.restore((err, result)=>{ downloadTask.restore((err, result)=>{
if (err) { if (err) {
console.error('Failed to resume the download task. Cause:' + err); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Download task resumed.'); console.info('Succeeded in resuming the download task.');
} else { } else {
console.error('Failed to resume the download task.'); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
### remove<sup>(deprecated)</sup> ### remove<sup>(deprecated)</sup>
remove(): Promise&lt;boolean&gt; remove(): Promise&lt;boolean&gt;
...@@ -1348,12 +1367,12 @@ remove(): Promise&lt;boolean&gt; ...@@ -1348,12 +1367,12 @@ remove(): Promise&lt;boolean&gt;
```js ```js
downloadTask.remove().then((result) => { downloadTask.remove().then((result) => {
if (result) { if (result) {
console.info('Download task removed.'); console.info('Succeeded in removing the download task.');
} else { } else {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
} }
}).catch ((err) => { }).catch ((err) => {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1381,13 +1400,13 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1381,13 +1400,13 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void
```js ```js
downloadTask.remove((err, result)=>{ downloadTask.remove((err, result)=>{
if(err) { if(err) {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Download task removed.'); console.info('Succeeded in removing the download task.');
} else { } else {
console.error('Failed to remove the download task.'); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -1415,9 +1434,9 @@ query(): Promise&lt;DownloadInfo&gt; ...@@ -1415,9 +1434,9 @@ query(): Promise&lt;DownloadInfo&gt;
```js ```js
downloadTask.query().then((downloadInfo) => { downloadTask.query().then((downloadInfo) => {
console.info('Download task queried. Data:' + JSON.stringify(downloadInfo)) console.info('Succeeded in querying the download task.')
}) .catch((err) => { }) .catch((err) => {
console.error('Failed to query the download task. Cause:' + err) console.error(`Failed to query the download task. Code: ${err.code}, message: ${err.message}`)
}); });
``` ```
...@@ -1445,9 +1464,9 @@ query(callback: AsyncCallback&lt;DownloadInfo&gt;): void ...@@ -1445,9 +1464,9 @@ query(callback: AsyncCallback&lt;DownloadInfo&gt;): void
```js ```js
downloadTask.query((err, downloadInfo)=>{ downloadTask.query((err, downloadInfo)=>{
if(err) { if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err)); console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info('download query success. data:'+ JSON.stringify(downloadInfo)); console.info('Succeeded in querying the download task.');
} }
}); });
``` ```
...@@ -1475,9 +1494,9 @@ queryMimeType(): Promise&lt;string&gt; ...@@ -1475,9 +1494,9 @@ queryMimeType(): Promise&lt;string&gt;
```js ```js
downloadTask.queryMimeType().then((data) => { downloadTask.queryMimeType().then((data) => {
console.info('Download task queried. Data:' + JSON.stringify(data)); console.info('Succeededto in querying the download MimeType.');
}).catch((err) => { }).catch((err) => {
console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err)) console.error(`Failed to query the download MimeType. Code: ${err.code}, message: ${err.message}`)
}); });
``` ```
...@@ -1505,9 +1524,9 @@ queryMimeType(callback: AsyncCallback&lt;string&gt;): void; ...@@ -1505,9 +1524,9 @@ queryMimeType(callback: AsyncCallback&lt;string&gt;): void;
```js ```js
downloadTask.queryMimeType((err, data)=>{ downloadTask.queryMimeType((err, data)=>{
if(err) { if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err)); console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info('Download task queried. data:' + JSON.stringify(data)); console.info('Succeeded in querying the download mimeType.');
} }
}); });
``` ```
...@@ -1536,12 +1555,12 @@ pause(): Promise&lt;void&gt; ...@@ -1536,12 +1555,12 @@ pause(): Promise&lt;void&gt;
```js ```js
downloadTask.pause().then((result) => { downloadTask.pause().then((result) => {
if (result) { if (result) {
console.info('Download task paused. '); console.info('Succeeded in pausing the download task.');
} else { } else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
} }
}).catch((err) => { }).catch((err) => {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1569,13 +1588,13 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -1569,13 +1588,13 @@ pause(callback: AsyncCallback&lt;void&gt;): void
```js ```js
downloadTask.pause((err, result)=>{ downloadTask.pause((err, result)=>{
if(err) { if(err) {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Download task paused. '); console.info('Succeeded in pausing the download task.');
} else { } else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result)); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -1604,13 +1623,13 @@ resume(): Promise&lt;void&gt; ...@@ -1604,13 +1623,13 @@ resume(): Promise&lt;void&gt;
```js ```js
downloadTask.resume().then((result) => { downloadTask.resume().then((result) => {
if (result) { if (result) {
console.info('Download task resumed.') console.info('Succeeded in resuming the download task.')
} else { } else {
console.error('Failed to resume the download task. '); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
} }
console.info('Download task resumed.') console.info('Succeeded in resuming the download task.')
}).catch((err) => { }).catch((err) => {
console.error('Failed to resume the download task. Cause:' + err); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1638,13 +1657,13 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -1638,13 +1657,13 @@ resume(callback: AsyncCallback&lt;void&gt;): void
```js ```js
downloadTask.resume((err, result)=>{ downloadTask.resume((err, result)=>{
if (err) { if (err) {
console.error('Failed to resume the download task. Cause:' + err); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
if (result) { if (result) {
console.info('Download task resumed.'); console.info('Succeeded in resuming the download task.');
} else { } else {
console.error('Failed to resume the download task.'); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
} }
}); });
``` ```
...@@ -1895,6 +1914,7 @@ on(event: "progress" | "completed" | "failed", callback: (progress: Progress) =& ...@@ -1895,6 +1914,7 @@ on(event: "progress" | "completed" | "failed", callback: (progress: Progress) =&
**示例:** **示例:**
```js ```js
let context;
let attachments = [{ let attachments = [{
name: "taskOnTest", name: "taskOnTest",
value: { value: {
...@@ -1928,16 +1948,19 @@ on(event: "progress" | "completed" | "failed", callback: (progress: Progress) =& ...@@ -1928,16 +1948,19 @@ on(event: "progress" | "completed" | "failed", callback: (progress: Progress) =&
let createOnCallback = (progress) => { let createOnCallback = (progress) => {
console.info('upload task completed.'); console.info('upload task completed.');
}; };
request.agent.create(globalThis.abilityContext, conf).then((task)=> { request.agent.create(context, conf).then((task)=> {
task.on('progress', createOnCallback); task.on('progress', createOnCallback);
task.on('completed', createOnCallback); task.on('completed', createOnCallback);
task.on('failed', createOnCallback); task.on('failed', createOnCallback);
console.info(`create a upload task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a upload task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
### off('progress'|'completed'|'failed')<sup>10+</sup> ### off('progress'|'completed'|'failed')<sup>10+</sup>
...@@ -1951,7 +1974,7 @@ off(event: "progress" | "completed" | "failed", callback?: (progress: Progress) ...@@ -1951,7 +1974,7 @@ off(event: "progress" | "completed" | "failed", callback?: (progress: Progress)
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| evt | string | 是 | 订阅的事件类型。<br>- 取值为'progress',表示任务进度;<br/>- 取值为'completed',表示任务已完成;<br/>- 取值为'failed',表示任务失败。 | | event | string | 是 | 订阅的事件类型。<br>- 取值为'progress',表示任务进度;<br/>- 取值为'completed',表示任务已完成;<br/>- 取值为'failed',表示任务失败。 |
| callback | function | 否 | 发生相关的事件时触发该回调方法,返回任务进度的数据结构| | callback | function | 否 | 发生相关的事件时触发该回调方法,返回任务进度的数据结构|
**错误码:** **错误码:**
...@@ -1965,6 +1988,7 @@ off(event: "progress" | "completed" | "failed", callback?: (progress: Progress) ...@@ -1965,6 +1988,7 @@ off(event: "progress" | "completed" | "failed", callback?: (progress: Progress)
**示例:** **示例:**
```js ```js
let context;
let attachments = [{ let attachments = [{
name: "taskOffTest", name: "taskOffTest",
value: { value: {
...@@ -1998,19 +2022,22 @@ off(event: "progress" | "completed" | "failed", callback?: (progress: Progress) ...@@ -1998,19 +2022,22 @@ off(event: "progress" | "completed" | "failed", callback?: (progress: Progress)
let createOffCallback = (progress) => { let createOffCallback = (progress) => {
console.info('upload task completed.'); console.info('upload task completed.');
}; };
request.agent.create(globalThis.abilityContext, conf).then((task)=> { request.agent.create(context, conf).then((task)=> {
task.on('progress', createOffCallback); task.on('progress', createOffCallback);
task.on('completed', createOffCallback); task.on('completed', createOffCallback);
task.on('failed', createOffCallback); task.on('failed', createOffCallback);
task.off('progress', createOffCallback); task.off('progress', createOffCallback);
task.off('completed', createOffCallback); task.off('completed', createOffCallback);
task.off('failed', createOffCallback); task.off('failed', createOffCallback);
console.info(`create a upload task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a upload task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
### start<sup>10+</sup> ### start<sup>10+</sup>
...@@ -2040,6 +2067,7 @@ start(callback: AsyncCallback&lt;void&gt;): void ...@@ -2040,6 +2067,7 @@ start(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2062,20 +2090,23 @@ start(callback: AsyncCallback&lt;void&gt;): void ...@@ -2062,20 +2090,23 @@ start(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.start((err) => { task.start((err) => {
if (err) { if (err) {
console.error(`Failed to start the download task, because: ${JSON.stringify(err)}`); console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info(`start a download task successfully. `); console.info(`Succeeded in starting a download task.`);
}) });
console.info(`create a download task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
### start<sup>10+</sup> ### start<sup>10+</sup>
...@@ -2105,6 +2136,7 @@ start(): Promise&lt;void&gt; ...@@ -2105,6 +2136,7 @@ start(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2127,18 +2159,21 @@ start(): Promise&lt;void&gt; ...@@ -2127,18 +2159,21 @@ start(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.start().then(() => { task.start().then(() => {
console.info(`start a download task successfully. `); console.info(`Succeeded in starting a download task.`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to start the download task, because: ${JSON.stringify(err)}`); console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`);
}); });
console.info(`create a download task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
### pause<sup>10+</sup> ### pause<sup>10+</sup>
...@@ -2167,6 +2202,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -2167,6 +2202,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2189,17 +2225,17 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -2189,17 +2225,17 @@ pause(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.pause((err) => { task.pause((err) => {
if (err) { if (err) {
console.error(`Failed to pause the download task, because: ${JSON.stringify(err)}`); console.error(`Failed to pause the download task, Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info(`pause a download task successfully. `); console.info(`Succeeded in pausing a download task. `);
}) });
console.info(`create a download task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2231,6 +2267,7 @@ pause(): Promise&lt;void&gt; ...@@ -2231,6 +2267,7 @@ pause(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2253,15 +2290,15 @@ pause(): Promise&lt;void&gt; ...@@ -2253,15 +2290,15 @@ pause(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.pause().then(() => { task.pause().then(() => {
console.info(`pause a upload task successfully. `); console.info(`Succeeded in pausing a download task. `);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to pause the upload task, because: ${JSON.stringify(err)}`); console.error(`Failed to pause the upload task, Code: ${err.code}, message: ${err.message}`);
}); });
console.info(`create a upload task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a upload task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2295,6 +2332,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -2295,6 +2332,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2317,15 +2355,17 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -2317,15 +2355,17 @@ resume(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.resume().then(() => { task.resume((err) => {
console.info(`resume a download task successfully. `); if (err) {
}).catch((err) => { console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`);
console.error(`Failed to resume the download task, because: ${JSON.stringify(err)}`); return;
}
console.info(`Succeeded in resuming a download task. `);
}); });
console.info(`create a download task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2359,6 +2399,7 @@ resume(): Promise&lt;void&gt; ...@@ -2359,6 +2399,7 @@ resume(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2381,17 +2422,15 @@ resume(): Promise&lt;void&gt; ...@@ -2381,17 +2422,15 @@ resume(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.resume((err) => { task.resume().then(() => {
if (err) { console.info(`Succeeded in resuming a download task. `);
console.error(`Failed to resume the download task, because: ${JSON.stringify(err)}`); }).catch((err) => {
return; console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`);
} });
console.info(`resume a download task successfully. `); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
})
console.info(`create a download task successfully. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2422,6 +2461,7 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2422,6 +2461,7 @@ stop(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2444,15 +2484,17 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2444,15 +2484,17 @@ stop(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.stop().then(() => { task.stop((err) => {
console.info(`stop a download task successfully. `); if (err) {
}).catch((err) => { console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`);
console.error(`Failed to stop the download task, because: ${JSON.stringify(err)}`); return;
}
console.info(`Succeeded in stopping a download task. `);
}); });
console.info(`create a download task successfully. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2483,6 +2525,7 @@ stop(): Promise&lt;void&gt; ...@@ -2483,6 +2525,7 @@ stop(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let context;
let conf = { let conf = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
...@@ -2505,17 +2548,15 @@ stop(): Promise&lt;void&gt; ...@@ -2505,17 +2548,15 @@ stop(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task) => { request.agent.create(context, conf).then((task) => {
task.stop((err) => { task.stop().then(() => {
if (err) { console.info(`Succeeded in stopping a download task. `);
console.error(`Failed to stop the download task, because: ${JSON.stringify(err)}`); }).catch((err) => {
return; console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`);
} });
console.info(`stop a download task successfully. `); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
})
console.info(`create a download task successfully. result: ${task.tid}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, because: ${JSON.stringify(err)}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2552,6 +2593,7 @@ create(context: BaseContext, conf: Conf, callback: AsyncCallback&lt;Task&gt;): v ...@@ -2552,6 +2593,7 @@ create(context: BaseContext, conf: Conf, callback: AsyncCallback&lt;Task&gt;): v
**示例:** **示例:**
```js ```js
let context;
let attachments = [{ let attachments = [{
name: "reeateTest", name: "reeateTest",
value: { value: {
...@@ -2582,15 +2624,18 @@ create(context: BaseContext, conf: Conf, callback: AsyncCallback&lt;Task&gt;): v ...@@ -2582,15 +2624,18 @@ create(context: BaseContext, conf: Conf, callback: AsyncCallback&lt;Task&gt;): v
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf, (err, task) => { request.agent.create(context, conf, (err, task) => {
if (err) { if (err) {
console.error(`Failed to create a upload task, because: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info(`create a upload task successfully. result: ${task.conf}`); console.info(`Succeeded in creating a download task. result: ${task.conf}`);
}); });
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
## request.agent.create<sup>10+</sup> ## request.agent.create<sup>10+</sup>
...@@ -2630,6 +2675,7 @@ create(context: BaseContext, conf: Conf): Promise&lt;Task&gt; ...@@ -2630,6 +2675,7 @@ create(context: BaseContext, conf: Conf): Promise&lt;Task&gt;
**示例:** **示例:**
```js ```js
let context;
let attachments = [{ let attachments = [{
name: "reeateTest", name: "reeateTest",
value: { value: {
...@@ -2660,13 +2706,16 @@ create(context: BaseContext, conf: Conf): Promise&lt;Task&gt; ...@@ -2660,13 +2706,16 @@ create(context: BaseContext, conf: Conf): Promise&lt;Task&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(globalThis.abilityContext, conf).then((task)=> { request.agent.create(context, conf).then((task)=> {
console.info(`create a upload task successfully. result: ${task.conf}`); console.info(`Succeeded in creating a download task. result: ${task.conf}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a upload task, because: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
> **说明:**
>
> 示例中context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。
## request.agent.remove<sup>10+</sup> ## request.agent.remove<sup>10+</sup>
...@@ -2697,10 +2746,10 @@ remove(id: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -2697,10 +2746,10 @@ remove(id: string, callback: AsyncCallback&lt;void&gt;): void
```js ```js
request.agent.remove("id", (err) => { request.agent.remove("id", (err) => {
if (err) { if (err) {
console.error(`Failed to remove a upload task, because: ${JSON.stringify(err)}`); console.error(`Failed to removing a download task, Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info(`remove a upload task successfully.`); console.info(`Succeeded in creating a download task.`);
}); });
``` ```
...@@ -2738,9 +2787,9 @@ remove(id: string): Promise&lt;void&gt; ...@@ -2738,9 +2787,9 @@ remove(id: string): Promise&lt;void&gt;
```js ```js
request.agent.remove("id").then(() => { request.agent.remove("id").then(() => {
console.info(`remove a upload task successfully. `); console.info(`Succeeded in removing a download task. `);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to remove a upload task, because: ${JSON.stringify(err)}`); console.error(`Failed to remove a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册