oh4.1怎么调用installer.getBundleInstaller安装这个应用成功后,自动拉起这个应用呢?

installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.install(hapFilePaths, installParam) .then((data: void) => { console.info('install successfully: ' + JSON.stringify(data)); setTimeout(()=>{ this.context.startAbility( { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', } ) .then(() => { // 执行正常业务 console.info('startAbility succeed'); }).catch((err: BusinessError) => { // 处理业务逻辑错误 console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`); }); },3000) }).catch((error: BusinessError) => { console.error('install failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); });
如上代码所示,我通过Install安装这个应用后,想通过context.startAbility立即拉起这个安装的这个应用,但是安装之后,调用context.startAbility拉不起来这个应用,是不是这样行不通,还是有别的方法求指教
您需要先 登录 才能评论/回答

全部评论(0)
目前好像安装或覆盖安装都拉不了。
备选方案:可以在安装应用时,给系统服务发一个event,另外一个系统服务(launcher或systemui)订阅,监听到event后,延时3秒左右去拉起你当前的应用。

2025-04-17 12:27:26
引用:“我现在在服务里面拉起不了应用,调用startAbility报错,说不是系统应用不能使用系统接口,可是服务已经是系统应用了,好奇怪”
bm dump -n xxx包名 | grep -i isSystemApp

OpenHarmony怎么自启动应用_云端筑梦-Laval社区 可以参考一下我之前写的,正常是能拉起来的,拉不起来可能得看一下日志分析一下了

2025-04-16 16:26:03