WantAgent模塊
WantAgent模塊提供了觸發(fā)、取消、比較WantAgent實例和獲取bundle名稱的能力,包括創(chuàng)建WantAgent實例、獲取實例的用戶ID、獲取want信息等。
說明:
導入模塊
import WantAgent from '@ohos.wantAgent';
開發(fā)前請熟悉鴻蒙開發(fā)指導文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
WantAgent.getWantAgent
getWantAgent(info: WantAgentInfo, callback: AsyncCallback): void
創(chuàng)建WantAgent(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
info | 是 | 否 | WantAgentInfo | 是 | WantAgent信息。 |
callback | 是 | 否 | AsyncCallback | 是 | 創(chuàng)建WantAgent的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
WantAgent.getWantAgent
getWantAgent(info: WantAgentInfo): Promise
創(chuàng)建WantAgent(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
info | 是 | 否 | WantAgentInfo | 是 | WantAgent信息。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式返回WantAgent。 |
示例:
import WantAgent from '@ohos.wantAgent';
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
});
WantAgent.getBundleName
getBundleName(agent: WantAgent, callback: AsyncCallback): void
獲取WantAgent實例的包名(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 獲取WantAgent實例的包名的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getBundleName回調(diào)
function getBundleNameCallback(err, data) {
console.info("========================== >getBundleNameCallback======================= >");
}
WantAgent.getBundleName(wantAgent, getBundleNameCallback)
WantAgent.getBundleName
getBundleName(agent: WantAgent): Promise
獲取WantAgent實例的包名(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式返回獲取WantAgent實例的包名。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent = data;
});
WantAgent.getBundleName(wantAgent).then((data) = > {
console.info("========================== >getBundleNameCallback======================= >");
});
WantAgent.getUid
getUid(agent: WantAgent, callback: AsyncCallback): void
獲取WantAgent實例的用戶ID(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 獲取WantAgent實例的用戶ID的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getUid回調(diào)
function getUidCallback(err, data) {
console.info("========================== >getUidCallback======================= >");
}
WantAgent.getUid(wantAgent, getUidCallback)
WantAgent.getUid
getUid(agent: WantAgent): Promise
獲取WantAgent實例的用戶ID(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式返回獲取WantAgent實例的用戶ID。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent = data;
});
WantAgent.getUid(wantAgent).then((data) = > {
console.info("========================== >getUidCallback======================= >");
});
WantAgent.getWant
getWant(agent: WantAgent, callback: AsyncCallback): void
獲取WantAgent對象的want(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
系統(tǒng)API : 此接口為系統(tǒng)接口,三方應(yīng)用不支持調(diào)用。
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 獲取WantAgent對象want的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//getWant回調(diào)
function getWantCallback(err, data) {
console.info("========================== >getWantCallback======================= >");
}
WantAgent.getWant(wantAgent, getWantCallback)
WantAgent.getWant
getWant(agent: WantAgent): Promise
獲取WantAgent對象的want(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
系統(tǒng)API : 此接口為系統(tǒng)接口,三方應(yīng)用不支持調(diào)用。
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式返回獲取WantAgent對象的want。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent = data;
});
WantAgent.getWant(wantAgent).then((data) = > {
console.info("========================== >getWantCallback======================= >");
});
WantAgent.cancel
cancel(agent: WantAgent, callback: AsyncCallback): void
取消WantAgent實例(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 取消WantAgent實例的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//cancel回調(diào)
function cancelCallback(err, data) {
console.info("========================== >cancelCallback======================= >");
}
WantAgent.cancel(wantAgent, cancelCallback)
WantAgent.cancel
cancel(agent: WantAgent): Promise
取消WantAgent實例(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式獲取異步返回結(jié)果。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent = data;
});
WantAgent.cancel(wantAgent).then((data) = > {
console.info("========================== >cancelCallback======================= >");
});
WantAgent.trigger
trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback): void
主動激發(fā)WantAgent實例(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
triggerInfo | 是 | 否 | TriggerInfo | 是 | TriggerInfo對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 主動激發(fā)WantAgent實例的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//trigger回調(diào)
function triggerCallback(data) {
console.info("========================== >triggerCallback======================= >");
}
var triggerInfo = {
code:0
}
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback)
WantAgent.equal
equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback): void
判斷兩個WantAgent實例是否相等(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
otherAgent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 判斷兩個WantAgent實例是否相等的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent1;
var wantAgent2;
//getWantAgent回調(diào)
function getWantAgentCallback(err, data) {
console.info("========================== >getWantAgentCallback======================= >");
if (err.code == 0) {
wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//equal回調(diào)
function equalCallback(err, data) {
console.info("========================== >equalCallback======================= >");
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)
WantAgent.equal
equal(agent: WantAgent, otherAgent: WantAgent): Promise
判斷兩個WantAgent實例是否相等(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
otherAgent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式返回獲取判斷兩個WantAgent實例是否相等的結(jié)果。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent1;
var wantAgent2;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent1 = data;
wantAgent2 = data;
});
WantAgent.equal(wantAgent1, wantAgent2).then((data) = > {
console.info("========================== >equalCallback======================= >");
});
WantAgent.getOperationType9+
getOperationType(agent: WantAgent, callback: AsyncCallback): void;
獲取一個WantAgent的OperationType信息(callback形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
callback | 是 | 否 | AsyncCallback | 是 | 獲取一個WantAgent的OperationType信息的回調(diào)方法。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent = data;
});
WantAgent.getOperationType(wantAgent, (OperationType) = > {
console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
})
WantAgent.getOperationType9+
getOperationType(agent: WantAgent): Promise;
獲取一個WantAgent的OperationType信息(Promise形式)。
系統(tǒng)能力 :SystemCapability.Ability.AbilityRuntime.Core
參數(shù):
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
agent | 是 | 否 | WantAgent | 是 | WantAgent對象。 |
返回值:
類型 | 說明 |
---|---|
Promise | 以Promise形式返回獲取optionType的結(jié)果。 |
示例:
import WantAgent from '@ohos.wantAgent';
//wantAgent對象
var wantAgent;
//WantAgentInfo對象
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) = > {
console.info("========================== >getWantAgentCallback======================= >");
wantAgent = data;
});
WantAgent.getOperationType(wantAgent).then((OperationType) = > {
console.log('getOperationType success, OperationType: ' + OperationType);
}).catch((err) = > {
console.log('getOperationType fail, err: ' + err);
})
WantAgentInfo
系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
wants | 是 | 是 | Array | 是 | 將被執(zhí)行的動作列表。 |
operationType | 是 | 是 | wantAgent.OperationType | 是 | 動作類型。 |
requestCode | 是 | 是 | number | 是 | 使用者定義的一個私有值。 |
wantAgentFlags | 是 | 是 | Array | 否 | 動作執(zhí)行屬性。 |
extraInfo | 是 | 是 | {[key: string]: any} | 否 | 額外數(shù)據(jù)。 |
WantAgentFlags
系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core
名稱 | 值 | 說明 |
---|---|---|
ONE_TIME_FLAG | WantAgentFlags | WantAgent僅能使用一次。 |
NO_BUILD_FLAG | WantAgentFlags | 如果描述WantAgent對象不存在,則不創(chuàng)建它,直接返回null。 |
CANCEL_PRESENT_FLAG | WantAgentFlags | 在生成一個新的WantAgent對象前取消已存在的一個WantAgent對象。 |
UPDATE_PRESENT_FLAG | WantAgentFlags | 使用新的WantAgent的額外數(shù)據(jù)替換已存在的WantAgent中的額外數(shù)據(jù)。 |
CONSTANT_FLAG | WantAgentFlags | WantAgent是不可變的。 |
REPLACE_ELEMENT | WantAgentFlags | 當前Want中的element屬性可被WantAgent.trigger()中Want的element屬性取代 |
REPLACE_ACTION | WantAgentFlags | 當前Want中的action屬性可被WantAgent.trigger()中Want的action屬性取代 |
REPLACE_URI | WantAgentFlags | 當前Want中的uri屬性可被WantAgent.trigger()中Want的uri屬性取代 |
REPLACE_ENTITIES | WantAgentFlags | 當前Want中的entities屬性可被WantAgent.trigger()中Want的entities屬性取代 |
REPLACE_BUNDLE | WantAgentFlags | 當前Want中的bundleName屬性可被WantAgent.trigger()中Want的bundleName屬性取代 |
OperationType
系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core
名稱 | 值 | 說明 |
---|---|---|
UNKNOWN_TYPE | OperationType | 不識別的類型。 |
START_ABILITY | OperationType | 開啟一個有頁面的Ability。 |
START_ABILITIES | OperationType | 開啟多個有頁面的Ability。 |
START_SERVICE | OperationType | 開啟一個無頁面的ability。 |
SEND_COMMON_EVENT | OperationType | 發(fā)送一個公共事件。 |
CompleteData
系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
info | 是 | 是 | WantAgent | 是 | 觸發(fā)的wantAgent。 |
want | 是 | 是 | Want | 是 | 存在的被觸發(fā)的want。 |
finalCode | 是 | 是 | number | 是 | 觸發(fā)wantAgent的請求代碼。 |
finalData | 是 | 是 | string | 否 | 公共事件收集的最終數(shù)據(jù)。 |
extraInfo | 是 | 是 | {[key: string]: any} | 否 | 額外數(shù)據(jù)。 |
HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
TriggerInfo
系統(tǒng)能力 :以下各項對應(yīng)的系統(tǒng)能力均為SystemCapability.Ability.AbilityRuntime.Core
名稱 | 可讀 | 可寫 | 類型 | 必填 | 描述 |
---|---|---|---|---|---|
code | 是 | 是 | number | 是 | result code。 |
want | 是 | 是 | Want | 否 | Want。 |
permission | 是 | 是 | string | 否 | 權(quán)限定義。 |
extraInfo | 是 | 是 | {[key: string]: any} | 否 | 額外數(shù)據(jù)。 |
審核編輯 黃宇
-
接口
+關(guān)注
關(guān)注
33文章
8447瀏覽量
150720 -
框架
+關(guān)注
關(guān)注
0文章
398瀏覽量
17404 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2302瀏覽量
42689
發(fā)布評論請先 登錄
相關(guān)推薦
評論