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

!12280 wantagent和datauriUtil文档

Merge pull request !12280 from zhuhan/wantagentdoc
......@@ -35,7 +35,7 @@
- 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.app.ability.wantConstant (wantConstant)](js-apis-app-ability-wantConstant.md)
- [@ohos.ability.wantConstant (wantConstant)](js-apis-ability-wantConstant.md)
......
# 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
## 导入模块
```js
```ts
import WantAgent from '@ohos.app.ability.wantAgent';
```
......@@ -27,15 +27,41 @@ getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
| info | WantAgentInfo | 是 | 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';
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
}
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -64,10 +90,18 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
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\>
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| 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';
......@@ -129,10 +190,12 @@ var wantAgentInfo = {
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
wantAgent = data;
}).catch((err) => {
console.info('getWantAgent failed!' + JSON.stringify(err.code) + JSON.stringify(err.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
| agent | WantAgent | 是 | 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';
//wantAgent对象
var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -199,16 +276,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getBundleName回调
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) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
try{
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\>
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| 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';
//wantAgent对象
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -271,17 +388,27 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
});
WantAgent.getBundleName(wantAgent).then((data) => {
console.info("==========================>getBundleNameCallback=======================>");
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
}
try {
WantAgent.getBundleName(wantAgent).then((data)=>{
console.info('getBundleName ok!' + JSON.stringify(data));
}).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
| agent | WantAgent | 是 | WantAgent对象。 |
| 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';
//wantAgent对象
var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -348,16 +490,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(err));
}
//getUid回调
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) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
try{
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\>
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| 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';
//wantAgent对象
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -420,22 +602,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
});
WantAgent.getUid(wantAgent).then((data) => {
console.info("==========================>getUidCallback=======================>");
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
}
try {
WantAgent.getUid(wantAgent).then((data)=>{
console.info('getUid ok!' + JSON.stringify(data));
}).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
getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
......@@ -453,24 +644,40 @@ getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
| agent | WantAgent | 是 | WantAgent对象。 |
| 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';
//wantAgent对象
var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -499,16 +706,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getWant回调
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
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) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
try{
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\>
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| 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';
//wantAgent对象
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -573,17 +820,27 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
});
WantAgent.getWant(wantAgent).then((data) => {
console.info("==========================>getWantCallback=======================>");
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
}
try {
WantAgent.getUid(wantAgent).then((data)=>{
console.info('getUid ok!' + JSON.stringify(data));
}).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
| agent | WantAgent | 是 | 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';
//wantAgent对象
var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -650,16 +922,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//cancel回调
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
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)
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
try {
WantAgent.cancel(wantAgent, getBundleNameCallback);
} 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\>
| --------------- | ------------------------------- |
| 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';
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -722,21 +1034,33 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
});
WantAgent.cancel(wantAgent).then((data) => {
console.info("==========================>cancelCallback=======================>");
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
}
try {
WantAgent.cancel(wantAgent).then((data)=>{
console.info('cancel ok!');
}).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
......@@ -754,24 +1078,43 @@ trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<Co
| triggerInfo | TriggerInfo | 是 | TriggerInfo对象。 |
| 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';
//wantAgent对象
var wantAgent;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
// triggerInfo
var triggerInfo = {
code: 0
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -800,21 +1143,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//trigger回调
function triggerCallback(data) {
console.info("==========================>triggerCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
var triggerInfo = {
code:0
//getUid回调
function triggerCallback(err, data) {
if(err) {
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)
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
try {
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback);
} 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\
| otherAgent | WantAgent | 是 | 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';
//wantAgent对象
var wantAgent1;
var wantAgent2;
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -884,16 +1251,32 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//equal回调
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
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) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
try{
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\>
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| 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';
//wantAgent对象
//wantAgent对象
var wantAgent1;
var wantAgent2;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -958,18 +1366,28 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent1 = data;
wantAgent2 = data;
});
WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
console.info("==========================>equalCallback=======================>");
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
}
try {
WantAgent.equal(wantAgent1,wantAgent2).then((data)=>{
console.info('equal ok!' + JSON.stringify(data));
}).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;
| agent | WantAgent | 是 | WantAgent对象。 |
| 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';
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -1024,17 +1467,31 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
});
WantAgent.getOperationType(wantAgent, (OperationType) => {
console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed' + JSON.stringify(wantAgent));
}
//getUid回调
function getOperationTypeCallback(err, data) {
if(err) {
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>;
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| 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';
//wantAgent对象
//wantAgent对象
var wantAgent;
//WantAgentInfo对象
var wantAgentInfo = {
wants: [
......@@ -1094,19 +1577,27 @@ var wantAgentInfo = {
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
//getWantAgent回调
function getWantAgentCallback(err, data) {
if (err == undefined) {
wantAgent = data;
});
WantAgent.getOperationType(wantAgent).then((OperationType) => {
console.log('getOperationType success, OperationType: ' + OperationType);
}).catch((err) => {
console.log('getOperationType fail, err: ' + err);
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
} else {
console.info('getWantAgent failed!' + JSON.stringify(wantAgent));
}
try {
WantAgent.getOperationType(wantAgent).then((data)=>{
console.info('getOperationType ok!' + JSON.stringify(data));
}).catch((err)=>{
console.info('getOperationType failed!' + JSON.stringify(err.code) + JSON.stringify(err.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实例和获取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.
先完成此消息的编辑!
想要评论请 注册