未验证 提交 877891e5 编写于 作者: O openharmony_ci 提交者: Gitee

!12280 wantagent和datauriUtil文档

Merge pull request !12280 from zhuhan/wantagentdoc
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
- application/[PermissionRequestResult (PermissionRequestResult)](js-apis-inner-application-permissionRequestResult.md) - application/[PermissionRequestResult (PermissionRequestResult)](js-apis-inner-application-permissionRequestResult.md)
- 通用 - 通用
- [@ohos.ability.dataUriUtils (DataUriUtils模块)](js-apis-ability-dataUriUtils.md) - [@ohos.app.ability.dataUriUtils (DataUriUtils模块)](js-apis-app-ability-dataUriUtils.md)
- [@ohos.ability.errorCode (ErrorCode)](js-apis-ability-errorCode.md) - [@ohos.ability.errorCode (ErrorCode)](js-apis-ability-errorCode.md)
- [@ohos.app.ability.wantConstant (wantConstant)](js-apis-app-ability-wantConstant.md) - [@ohos.app.ability.wantConstant (wantConstant)](js-apis-app-ability-wantConstant.md)
- [@ohos.ability.wantConstant (wantConstant)](js-apis-ability-wantConstant.md) - [@ohos.ability.wantConstant (wantConstant)](js-apis-ability-wantConstant.md)
......
# DataUriUtils模块 # DataUriUtils模块
DataUriUtils模块提供用于处理使用DataAbilityHelper方案的对象的实用程序类的能力,包括获取,添加,更新给定uri的路径组件末尾的ID。 DataUriUtils模块提供用于处理使用DataAbilityHelper方案的对象的实用程序类的能力,包括获取,添加,更新给定uri的路径组件末尾的ID。本模块将被app.ability.dataUriUtils模块,建议优先使用[@ohos.app.ability.dataUriUtils](js-apis-app-ability-dataUriUtils.md)模块。
> **说明:** > **说明:**
> >
......
# DataUriUtils模块
DataUriUtils模块提供用于处理使用DataAbilityHelper方案的对象的实用程序类的能力,包括获取,添加,更新给定uri的路径末尾的ID。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```ts
import dataUriUtils from '@ohos.app.ability.dataUriUtils';
```
## dataUriUtils.getId
getId(uri: string): number
获取附加到给定uri的路径末尾的ID。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ---- | ------ | ---- | --------------------------- |
| uri | string | 是 | 指示要从中获取ID的uri对象。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| number | 附加到uri路径末尾的ID。 |
**示例:**
```ts
try {
var id = dataUriUtils.getId("com.example.dataUriUtils/1221")
console.info('get id: ' + id)
} catch(err) {
console.error('get id err ,check the uri' + err)
}
```
## dataUriUtils.attachId
attachId(uri: string, id: number): string
将给定ID附加到给定uri的路径末尾。可用于生成新的uri。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ---- | ------ | ---- | --------------------------- |
| uri | string | 是 | 指示要从中获取ID的uri对象。 |
| id | number | 是 | 指示要附加的ID。 |
**返回值:**
| 类型 | 说明 |
| ------ | --------------------- |
| string | 附加给定ID的uri对象。 |
**示例:**
```ts
var idint = 1122;
try {
var uri = dataUriUtils.attachId(
"com.example.dataUriUtils",
idint,
)
console.info('attachId the uri is: ' + uri)
} catch (err) {
console.error('get id err ,check the uri' + err)
}
```
## dataUriUtils.deleteId
deleteId(uri: string): string
从给定uri的路径的末尾删除ID。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ---- | ------ | ---- | --------------------------- |
| uri | string | 是 | 指示要从中删除ID的uri对象。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------- |
| string | ID已删除的uri对象。 |
**示例:**
```ts
try {
var uri = dataUriUtils.deleteId("com.example.dataUriUtils/1221")
console.info('delete id with the uri is: ' + uri)
} catch(err) {
console.error('delete uri err, check the input uri' + err)
}
```
## dataUriUtils.updateId
updateId(uri: string, id: number): string
更新指定uri中的ID。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ---- | ------ | ---- | ------------------- |
| uri | string | 是 | 指示要更新的uri对象。 |
| id | number | 是 | 指示新ID。 |
**返回值:**
| 类型 | 说明 |
| ------ | --------------- |
| string | 更新的uri对象。 |
**示例:**
```ts
try {
var idint = 1122;
var uri = dataUriUtils.updateId(
"com.example.dataUriUtils",
idint
)
} catch (err) {
console.error('delete uri err, check the input uri' + err)
}
```
# WantAgent模块 # app.ability.WantAgent模块
WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle名称的能力,包括创建WantAgent实例、获取实例的用户ID、获取want信息等 app.ability.WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle名称的能力,包括创建WantAgent实例、获取实例的用户ID、获取want信息等。该模块将会取代[@ohos.wantAgent](js-apis-wantAgent.md)模块,建议优先使用本模块
> **说明:** > **说明:**
> >
...@@ -8,7 +8,7 @@ WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle ...@@ -8,7 +8,7 @@ WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle
## 导入模块 ## 导入模块
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
``` ```
...@@ -27,15 +27,41 @@ getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void ...@@ -27,15 +27,41 @@ getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
| info | WantAgentInfo | 是 | WantAgent信息。 | | info | WantAgentInfo | 是 | WantAgent信息。 |
| callback | AsyncCallback\<WantAgent\> | 是 | 创建WantAgent的回调方法。 | | callback | AsyncCallback\<WantAgent\> | 是 | 创建WantAgent的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//getWantAgent回调 //wantAgent对象
function getWantAgentCallback(err, data) { var wantAgent;
console.info("==========================>getWantAgentCallback=======================>");
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -64,10 +90,18 @@ var wantAgentInfo = { ...@@ -64,10 +90,18 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
} catch (paramError) { if (err == undefined) {
console.log("error: " + paramError.code + ", " + paramError.message); wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(err));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -93,9 +127,36 @@ getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> ...@@ -93,9 +127,36 @@ getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 | | Promise\<WantAgent\> | 以Promise形式返回WantAgent。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
...@@ -129,10 +190,12 @@ var wantAgentInfo = { ...@@ -129,10 +190,12 @@ var wantAgentInfo = {
try { try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>"); wantAgent = data;
}); }).catch((err) => {
} catch (paramError) { console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
console.log("error: " + paramError.code + ", " + paramError.message); });
} catch (err) {
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -153,24 +216,38 @@ getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void ...@@ -153,24 +216,38 @@ getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void
| agent | WantAgent | 是 | WantAgent对象。 | | agent | WantAgent | 是 | WantAgent对象。 |
| callback | AsyncCallback\<string\> | 是 | 获取WantAgent实例的包名的回调方法。 | | callback | AsyncCallback\<string\> | 是 | 获取WantAgent实例的包名的回调方法。 |
**错误码:**
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -199,16 +276,31 @@ var wantAgentInfo = { ...@@ -199,16 +276,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getBundleName回调 //getBundleName回调
function getBundleNameCallback(err, data) { function getBundleNameCallback(err, data) {
console.info("==========================>getBundleNameCallback=======================>"); if(err) {
console.info('getBundleName failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('getBundleName ok!' + JSON.stringify(data));
}
}
try {
WantAgent.getBundleName(wantAgent, getBundleNameCallback);
} catch(err) {
console.info('getBundleName failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
WantAgent.getBundleName(wantAgent, getBundleNameCallback) }
} catch (paramError) { try{
console.log("error: " + paramError.code + ", " + paramError.message); WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -234,15 +326,40 @@ getBundleName(agent: WantAgent): Promise\<string\> ...@@ -234,15 +326,40 @@ getBundleName(agent: WantAgent): Promise\<string\>
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 | | Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象
//wantAgent对象
var wantAgent; var wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -271,17 +388,27 @@ var wantAgentInfo = { ...@@ -271,17 +388,27 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent = data; wantAgent = data;
}); } else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
WantAgent.getBundleName(wantAgent).then((data) => { }
console.info("==========================>getBundleNameCallback=======================>"); try {
}); WantAgent.getBundleName(wantAgent).then((data)=>{
} catch (paramError) { console.info('getBundleName ok!' + JSON.stringify(data));
console.log("error: " + paramError.code + ", " + paramError.message); }).catch((err)=>{
console.info('getBundleName failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
})
} catch(err){
console.info('getBundleName failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -302,24 +429,39 @@ getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void ...@@ -302,24 +429,39 @@ getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void
| agent | WantAgent | 是 | WantAgent对象。 | | agent | WantAgent | 是 | WantAgent对象。 |
| callback | AsyncCallback\<number\> | 是 | 获取WantAgent实例的用户ID的回调方法。 | | callback | AsyncCallback\<number\> | 是 | 获取WantAgent实例的用户ID的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -348,16 +490,31 @@ var wantAgentInfo = { ...@@ -348,16 +490,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(err));
}
//getUid回调 //getUid回调
function getUidCallback(err, data) { function getUidCallback(err, data) {
console.info("==========================>getUidCallback=======================>"); if(err) {
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('getUid ok!' + JSON.stringify(data));
}
}
try {
WantAgent.getUid(wantAgent, getUidCallback);
} catch(err) {
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
WantAgent.getUid(wantAgent, getUidCallback) }
} catch (paramError) { try{
console.log("error: " + paramError.code + ", " + paramError.message); WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -383,15 +540,40 @@ getUid(agent: WantAgent): Promise\<number\> ...@@ -383,15 +540,40 @@ getUid(agent: WantAgent): Promise\<number\>
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 | | Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象
//wantAgent对象
var wantAgent; var wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -420,22 +602,31 @@ var wantAgentInfo = { ...@@ -420,22 +602,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent = data; wantAgent = data;
}); } else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
WantAgent.getUid(wantAgent).then((data) => { }
console.info("==========================>getUidCallback=======================>"); try {
}); WantAgent.getUid(wantAgent).then((data)=>{
} catch (paramError) { console.info('getUid ok!' + JSON.stringify(data));
console.log("error: " + paramError.code + ", " + paramError.message); }).catch((err)=>{
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
})
} catch(err){
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
## WantAgent.getWant ## WantAgent.getWant
getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
...@@ -453,24 +644,40 @@ getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void ...@@ -453,24 +644,40 @@ getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
| agent | WantAgent | 是 | WantAgent对象。 | | agent | WantAgent | 是 | WantAgent对象。 |
| callback | AsyncCallback\<Want\> | 是 | 获取WantAgent对象want的回调方法。 | | callback | AsyncCallback\<Want\> | 是 | 获取WantAgent对象want的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
|错误码ID |错误信息 |
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -499,16 +706,31 @@ var wantAgentInfo = { ...@@ -499,16 +706,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
if (err == undefined) {
//getWant回调 wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
function getWantCallback(err, data) { function getWantCallback(err, data) {
console.info("==========================>getWantCallback=======================>"); if(err) {
console.info('getWant failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('getWant ok!' + JSON.stringify(data));
}
}
try {
WantAgent.getWant(wantAgent, getBundleNameCallback);
} catch(err) {
console.info('getWant failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
WantAgent.getWant(wantAgent, getWantCallback) }
} catch (paramError) { try{
console.log("error: " + paramError.code + ", " + paramError.message); WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -536,15 +758,40 @@ getWant(agent: WantAgent): Promise\<Want\> ...@@ -536,15 +758,40 @@ getWant(agent: WantAgent): Promise\<Want\>
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Want\> | 以Promise形式返回获取WantAgent对象的want。 | | Promise\<Want\> | 以Promise形式返回获取WantAgent对象的want。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象
//wantAgent对象
var wantAgent; var wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -573,17 +820,27 @@ var wantAgentInfo = { ...@@ -573,17 +820,27 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent = data; wantAgent = data;
}); } else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
WantAgent.getWant(wantAgent).then((data) => { }
console.info("==========================>getWantCallback=======================>"); try {
}); WantAgent.getUid(wantAgent).then((data)=>{
} catch (paramError) { console.info('getUid ok!' + JSON.stringify(data));
console.log("error: " + paramError.code + ", " + paramError.message); }).catch((err)=>{
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
})
} catch(err){
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -604,24 +861,39 @@ cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void ...@@ -604,24 +861,39 @@ cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void
| agent | WantAgent | 是 | WantAgent对象。 | | agent | WantAgent | 是 | WantAgent对象。 |
| callback | AsyncCallback\<void\> | 是 | 取消WantAgent实例的回调方法。 | | callback | AsyncCallback\<void\> | 是 | 取消WantAgent实例的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -650,16 +922,31 @@ var wantAgentInfo = { ...@@ -650,16 +922,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
if (err == undefined) {
//cancel回调 wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
function cancelCallback(err, data) { function cancelCallback(err, data) {
console.info("==========================>cancelCallback=======================>"); if(err) {
console.info('cancel failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('cancel ok!');
}
} }
WantAgent.cancel(wantAgent, cancelCallback) try {
} catch (paramError) { WantAgent.cancel(wantAgent, getBundleNameCallback);
console.log("error: " + paramError.code + ", " + paramError.message); } catch(err) {
console.info('cancel failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -685,15 +972,40 @@ cancel(agent: WantAgent): Promise\<void\> ...@@ -685,15 +972,40 @@ cancel(agent: WantAgent): Promise\<void\>
| --------------- | ------------------------------- | | --------------- | ------------------------------- |
| Promise\<void\> | 以Promise形式获取异步返回结果。 | | Promise\<void\> | 以Promise形式获取异步返回结果。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -722,21 +1034,33 @@ var wantAgentInfo = { ...@@ -722,21 +1034,33 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent = data; wantAgent = data;
}); } else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
WantAgent.cancel(wantAgent).then((data) => { }
console.info("==========================>cancelCallback=======================>"); try {
}); WantAgent.cancel(wantAgent).then((data)=>{
} catch (paramError) { console.info('cancel ok!');
console.log("error: " + paramError.code + ", " + paramError.message); }).catch((err)=>{
console.info('cancel failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
})
} catch(err){
console.info('cancel failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
//TODO WantAgent.trigger Callback
## WantAgent.trigger ## WantAgent.trigger
...@@ -754,24 +1078,43 @@ trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<Co ...@@ -754,24 +1078,43 @@ trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<Co
| triggerInfo | TriggerInfo | 是 | TriggerInfo对象。 | | triggerInfo | TriggerInfo | 是 | TriggerInfo对象。 |
| callback | AsyncCallback\<CompleteData\> | 否 | 主动激发WantAgent实例的回调方法。 | | callback | AsyncCallback\<CompleteData\> | 否 | 主动激发WantAgent实例的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
// triggerInfo
//getWantAgent回调 var triggerInfo = {
function getWantAgentCallback(err, data) { code: 0
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
} }
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -800,21 +1143,31 @@ var wantAgentInfo = { ...@@ -800,21 +1143,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
if (err == undefined) {
//trigger回调 wantAgent = data;
function triggerCallback(data) { } else {
console.info("==========================>triggerCallback=======================>"); console.info('getWantAgent failed' + JSON.stringify(wantAgent));
} }
//getUid回调
function triggerCallback(err, data) {
var triggerInfo = { if(err) {
code:0 console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('getUid ok!' + JSON.stringify(data));
}
} }
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback) try {
} catch (paramError) { WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
console.log("error: " + paramError.code + ", " + paramError.message); } catch(err) {
console.info('getUid failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -836,26 +1189,40 @@ equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\ ...@@ -836,26 +1189,40 @@ equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\
| otherAgent | WantAgent | 是 | WantAgent对象。 | | otherAgent | WantAgent | 是 | WantAgent对象。 |
| callback | AsyncCallback\<boolean\> | 是 | 判断两个WantAgent实例是否相等的回调方法。 | | callback | AsyncCallback\<boolean\> | 是 | 判断两个WantAgent实例是否相等的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent1; var wantAgent1;
var wantAgent2; var wantAgent2;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -884,16 +1251,32 @@ var wantAgentInfo = { ...@@ -884,16 +1251,32 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) function getWantAgentCallback(err, data) {
if (err == undefined) {
//equal回调 wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
function equalCallback(err, data) { function equalCallback(err, data) {
console.info("==========================>equalCallback=======================>"); if(err) {
console.info('equal failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('equal ok!' + JSON.stringify(data));
}
}
try {
WantAgent.equal(wantAgent1,wantAgent2,equalCallback);
} catch(err) {
console.info('equal failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
WantAgent.equal(wantAgent1, wantAgent2, equalCallback) }
} catch (paramError) { try{
console.log("error: " + paramError.code + ", " + paramError.message); WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -920,16 +1303,41 @@ equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> ...@@ -920,16 +1303,41 @@ equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。 | | Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象
//wantAgent对象
var wantAgent1; var wantAgent1;
var wantAgent2; var wantAgent2;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -958,18 +1366,28 @@ var wantAgentInfo = { ...@@ -958,18 +1366,28 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent1 = data; wantAgent1 = data;
wantAgent2 = data; wantAgent2 = data;
}); } else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
WantAgent.equal(wantAgent1, wantAgent2).then((data) => { }
console.info("==========================>equalCallback=======================>"); try {
}); WantAgent.equal(wantAgent1,wantAgent2).then((data)=>{
} catch (paramError) { console.info('equal ok!' + JSON.stringify(data));
console.log("error: " + paramError.code + ", " + paramError.message); }).catch((err)=>{
console.info('equal failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
})
} catch(err){
console.info('equal failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -988,14 +1406,39 @@ getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void; ...@@ -988,14 +1406,39 @@ getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void;
| agent | WantAgent | 是 | WantAgent对象。 | | agent | WantAgent | 是 | WantAgent对象。 |
| callback | AsyncCallback\<number> | 是 | 获取一个WantAgent的OperationType信息的回调方法。 | | callback | AsyncCallback\<number> | 是 | 获取一个WantAgent的OperationType信息的回调方法。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -1024,17 +1467,31 @@ var wantAgentInfo = { ...@@ -1024,17 +1467,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent = data; wantAgent = data;
}); } else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
WantAgent.getOperationType(wantAgent, (OperationType) => { }
console.log('----------- getOperationType ----------, OperationType: ' + OperationType); //getUid回调
}) function getOperationTypeCallback(err, data) {
} catch (paramError) { if(err) {
console.log("error: " + paramError.code + ", " + paramError.message); console.info('getOperationType failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} else {
console.info('getOperationType ok!' + JSON.stringify(data));
}
}
try {
WantAgent.getOperationTypeCallback(wantAgent, getBundleNameCallback);
} catch(err) {
console.info('getOperationTypeCallback failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
...@@ -1058,14 +1515,40 @@ getOperationType(agent: WantAgent): Promise\<number>; ...@@ -1058,14 +1515,40 @@ getOperationType(agent: WantAgent): Promise\<number>;
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number> | 以Promise形式返回获取operationType的结果。 | | Promise\<number> | 以Promise形式返回获取operationType的结果。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
|-----------|--------------------|
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong.|
| 16000003 | Input error. The specified id does not exist.|
| 16000004 | Visibility verification failed.|
| 16000006 | Can not cross user operations.|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000008 | Crowdtest App Expiration.|
| 16000009 | Can not start ability in wukong mode.|
| 16000010 | Can not operation with continue flag.|
| 16000011 | Context does not exist.|
| 16000050 | Internal Error.|
| 16000051 | Network error. The network is abnormal.|
| 16000052 | Free install not support. The applicaiotn dose not support free install.|
| 16000053 | Not top ability. The application is not top ability.|
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry.|
| 16000055 | Free install timeout.|
| 16000056 | Can not free install other ability.|
| 16000057 | Not support cross device free install.|
| 16000101 | execute shell command failed.|
| 16000151 | Invalid wantagent object.|
| 16000152 | wantAgent object not found.|
| 16000153 | wangAgent object canceled.|
**示例:** **示例:**
```js ```ts
import WantAgent from '@ohos.app.ability.wantAgent'; import WantAgent from '@ohos.app.ability.wantAgent';
//wantAgent对象 //wantAgent对象
var wantAgent; var wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
var wantAgentInfo = { var wantAgentInfo = {
wants: [ wants: [
...@@ -1094,19 +1577,27 @@ var wantAgentInfo = { ...@@ -1094,19 +1577,27 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
try { //getWantAgent回调
WantAgent.getWantAgent(wantAgentInfo).then((data) => { function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>"); if (err == undefined) {
wantAgent = data; wantAgent = data;
}); } else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
WantAgent.getOperationType(wantAgent).then((OperationType) => { }
console.log('getOperationType success, OperationType: ' + OperationType); try {
}).catch((err) => { WantAgent.getOperationType(wantAgent).then((data)=>{
console.log('getOperationType fail, err: ' + err); console.info('getOperationType ok!' + JSON.stringify(data));
}) }).catch((err)=>{
} catch (paramError) { console.info('getOperationType failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
console.log("error: " + paramError.code + ", " + paramError.message); })
} catch(err){
console.info('getOperationType failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
}
}
try{
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback);
} catch(err){
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.message));
} }
``` ```
......
# WantAgent模块 # WantAgent模块
WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle参数名的能力,包括创建WantAgent实例、获取实例的用户ID、获取want信息等。 WantAgent模块提供了触发、取消、比较WantAgent实例和获取bundle名称的能力,包括创建WantAgent实例、获取实例的用户ID、获取want信息等。
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 7开始支持,从API version 9废弃,替换模块为[@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md)。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持,从API version 9废弃,替换模块为[@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md)。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册