通知消息点击隐式匹配打开ability失败。
传入abilityName必须为空,action不为空也可以拉起。
module.json5中定义:
{
"name": "TestAbilityA",
"srcEntry": "./ets/testabilityA/TestAbilityA.ets",
"description": "$string:TestAbility1_desc",
"icon": "$media:icon",
"label": "$string:TestAbility1_label",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"entities": [
"entity.open.page.a"
],
"actions": [
"action.open.page.a"
],
"uris": [
{
"scheme": "https",
"host": "xxx",
},
{
"scheme": "http",
}
]
}
]
}
通知方法:
{
"name": "TestAbilityA",
"srcEntry": "./ets/testabilityA/TestAbilityA.ets",
"description": "$string:TestAbility1_desc",
"icon": "$media:icon",
"label": "$string:TestAbility1_label",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"entities": [
"entity.open.page.a"
],
"actions": [
"action.open.page.a"
],
"uris": [
{
"scheme": "https",
"host": "xxx",
},
{
"scheme": "http",
}
]
}
]
}const TAG: string = '[PublishOperation]';
const DOMAIN_NUMBER: number = 0xFF00;
let wantAgentObj:WantAgent; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [
{
deviceId: '',
bundleName: 'cxxx',
abilityName: "",
action: 'entity.open.page.a',
entities: [],
uri: '',
parameters: {}
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
};
// 创建WantAgent
wantAgent.getWantAgent(wantAgentInfo, (err: BusinessError, data:WantAgent) => {
if (err) {
hilog.error(DOMAIN_NUMBER, TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`);
return;
}
hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in getting want agent.');
wantAgentObj = data;
let notificationRequest: notificationManager.NotificationRequest = {
id: 1,
wantAgent:wantAgentObj,
content: {
notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 普通文本类型通知
normal: {
title: 'test_title',
text: 'test_text',
additionalText: 'test_additionalText',
}
}
};
notificationManager.publish(notificationRequest, (err: BusinessError) => {
if (err) {
hilog.error(DOMAIN_NUMBER, TAG, `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
return;
}
hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
});
});
1、如果module.json5中的AbilityA的skills中仅配置了actions,则可以直接通过want-action做条件进行拉起。
2、如果module.json5中的AbilityA的skills中不仅需要配置了actions还需要配置uris,如果此时依然只希望通过actions进行拉起,则需要将actions和uris单独作为skills的子项进行配置,而不能仅作为一个子项进行配。