arkts为通知添加行为意图--点击按钮执行时闪退
arkts为通知添加行为意图--点击按钮执行时闪退
参考:
各位老师帮忙看下哪里不对呢?
let wantAgentObj = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型。
let wantAgentInfo = {
wants: [
{
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'com.example.myapplication.EntryAbility',
action: '',
entities: [],
uri: '',
parameters: {}
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
}
import NotificationManager from '@ohos.notificationManager';
import image from '@ohos.multimedia.image';
import wantAgent from '@ohos.app.ability.wantAgent';
//为通知添加行为意图,点击通知栏启动相关app应用程序,呼出对应应用程序
let wantAgentObj = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型。
let wantAgentInfo = {
wants: [
{
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'com.example.myapplication.EntryAbility',
action: '',
entities: [],
uri: '',
parameters: {}
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
}
// 创建WantAgent
wantAgent.getWantAgent(wantAgentInfo, (err, data) => {
if (err) {
console.error('[WantAgent]getWantAgent err=' + JSON.stringify(err));
} else {
console.info('[WantAgent]getWantAgent success');
wantAgentObj = data;
}
});
// 构造NotificationRequest对象行为意图
let notificationRequest_behavior = {
content: {
contentType: NotificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: '行为意图Test_Title_呼出app',
text: '行为意图Test_Text',
additionalText: 'Test_AdditionalText',
},
},
id: 6,
label: 'TEST',
wantAgent: wantAgentObj,
}
Button('行为意图通知测试_呼出app')
.onClick(()=>{
NotificationManager.publish(notificationRequest_behavior,(err)=>{
if(err)
{
console.error(`行为意图通知测试失败,err[${err}]`);
return;
}
console.info('行为意图通知测试成功')
});
})
欢迎讨论,相互学习。
cdtxw@foxmail.com