HarmonyOS鸿蒙Next中调用installer.getBundleInstaller接口自己安装自己,想更新覆盖之后再重新启动,发现方法没有执行,不能实现安装后应用自动起来

HarmonyOS鸿蒙Next中调用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拉不起来这个应用,是不是这样行不通,感觉覆盖安装之后,.then后的方法没有执行,下面是日志


更多关于HarmonyOS鸿蒙Next中调用installer.getBundleInstaller接口自己安装自己,想更新覆盖之后再重新启动,发现方法没有执行,不能实现安装后应用自动起来的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

目前好像安装或覆盖安装都拉不了。

备选方案:可以在安装应用时,给系统服务发一个event,另外一个系统服务(launcher或systemui)订阅,监听到event后,延时3秒左右去拉起你当前的应用。

参考:https://laval.csdn.net/user/discuss/67ff64f3e985815179717aca

更多关于HarmonyOS鸿蒙Next中调用installer.getBundleInstaller接口自己安装自己,想更新覆盖之后再重新启动,发现方法没有执行,不能实现安装后应用自动起来的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,调用installer.getBundleInstaller接口进行自更新时,应用在安装完成后不会自动重启。这是因为系统出于安全考虑,禁止应用在安装过程中自动重启。建议通过以下方式实现更新后重启:在安装完成后,通过系统广播或通知用户手动重启应用,或使用Ability的生命周期方法在应用重新启动时检查并应用更新。

回到顶部