张跃斌|
UI
DevEco Studio
关于使用显示want拉起ability的问题。
使用显示want可以拉起自己的ability,而无法拉起其它应用的ability,错误提示如下:
Device info:OpenHarmony 3.2
Build info:OpenHarmony 3.2.9.1
Module name:com.example.kkkk
Version:1.0.0
Pid:4640
Uid:20040005
Lifetime: 0.000000s
Js-Engine: ark
page: pages/Index.js
Error message: Invalid parameter
请问各位大佬是怎么回事呀?谢谢!
2
浏览324 发布于2024-01-09 22:23山西
全部评论
最多点赞
最新发布
最早发布
陌上
贴一下源代码
1楼回复于2024-01-10 00:41 来自山东
张跃斌共有2个文件,一个是zyb.ets ,如下: /* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0h+-/$%-+ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent'; import notification from '@ohos.notificationManager'; import hilog from '@ohos.hilog'; /** * Obtains the WantAgent of an application. * * @returns WantAgent of an application. */ export function createWantAgent(bundleName: string, abilityName: string): Promise<WantAgent> { let wantAgentInfo = { wants: [ { deviceId: '', bundleName: bundleName, abilityName: abilityName, action: '', entities: [], uri: '', parameters: {} } ], operationType: wantAgent.OperationType.START_ABILITY, requestCode: 0, wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG] } as wantAgent.WantAgentInfo; return wantAgent.getWantAgent(wantAgentInfo); } /** * Publish notification. * * @param progress Download progress * @param title Notification title. * @param wantAgentObj The want of application. */ export function publishNotification( wantAgentObj: WantAgent) { let template:notification.NotificationTemplate = { name: 'downloadTemplate', data: { progressValue: 1, progressMaxValue: 100, isProgressIndeterminate: false } }; let notificationRequest: notification.NotificationRequest = { id: 1000, slotType: notification.SlotType.CONTENT_INFORMATION, // Construct a progress bar template. The name field must be set to downloadTemplate. template: template, content: { contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, normal: { title: "test", text: 'test', additionalText: "haha" } }, wantAgent: wantAgentObj }; notification.publish(notificationRequest).catch((err: Error) => { console.log(JSON.stringify(err)); }); } /** * open notification permission */ export function openNotificationPermission() { notification.requestEnableNotification().then(() => { console.log('Enable notification success'); }).catch((err) => { console.log(JSON.stringify(err)); }); } 另一个是index.ets,如下: //import WantAgent from '@ohos.wantAgent'; import common from '@ohos.app.ability.common'; import vibrator from '@ohos.vibrator'; import NotificationManager from '@ohos.notificationManager'; import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent'; import { createWantAgent, publishNotification, openNotificationPermission } from '../zyb'; //import notification from '@ohos.notification'; @Entry @Component struct Index { @State message: string = 'Hello World' private wantAgentObj: WantAgent = new Object(); private context = getContext(this) as common.UIAbilityContext; aboutToAppear(){ } build() { Flex({direction:FlexDirection.Column,justifyContent:FlexAlign.SpaceEvenly}) { Text(this.message) .height('10%') .fontSize(30) .fontWeight(FontWeight.Bold) Button('创建') .width(200) .height('10%') .fontSize(30) .onClick( () => { openNotificationPermission(); //let bname=this.context.abilityInfo.bundleName; //let aname = this.context.abilityInfo.name; let bname='com.example.hhh'; let aname='EntryAbility'; createWantAgent(bname,aname).then(want => { this.wantAgentObj = want; }).catch((err: Error) => { console.log(JSON.stringify(err)); }); }) Button('发布') .width(200) .height('10%') .fontSize(30) .onClick(()=>{ publishNotification(this.wantAgentObj); }) } .padding(50) .height('100%') } }function sleep(arg0: number) { throw new Error('Function not implemented.'); } 麻烦您了,提前谢谢啦。展开全部2024-01-10 21:14 来自山西
写回答
所见即所得编辑器, editor1
工具栏 撤消 快捷键 Ctrl+Z 重做 快捷键 Ctrl+Y 格式刷 快捷键 Ctrl+Shift+C 清除格式 加粗 快捷键 Ctrl+B 倾斜 快捷键 Ctrl+I 下划线 快捷键 Ctrl+U 删除线格式调整字号 文本颜色 背景颜色 增加缩进量 减少缩进量 左对齐 居中 右对齐 两端对齐段落间距行间距 项目列表 编号列表 插入水平线 块引用 插入/编辑超链接 快捷键 Ctrl+K 取消超链接 图片 表格 上传附件 导入Word 插入代码 MD编辑器 全屏模式
0/50000
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
相关推荐
换一批
1
HarmonyOS 如何调整新拉起的Ability窗口的显示层级(API12+)
2
HarmonyOS 存在包含多个Ability的应用,是否支持在非EntryAbility里通过App Linking拉起三方应用,再由三方应用回调到了EntryAbility?(API12+)
3
HarmonyOS 2个Ability怎么进行消息互通 (API12+)
4
HarmonyOS 从一个Ability拉起一个新Ability时不支持配置过渡动画(API12+)
5
HarmonyOS windowVisibilityChange回调结果错误 (API12+)
6
HarmonyOS 如何通过want信息来判断拉起来源?(API12+)
7
HarmonyOS 拉起picker时,是否可以使用want中的parameters传递pixelMap (API12+)
8
HarmonyOS 单元测试框架多个测试用例使用的问题(API12+)
了解社区公约,与您携手共创和谐专业的开发者社区。




































苏公安网备 32011402010933号