HarmonyOS鸿蒙Next中如何获取应用的包名和唯一标识

HarmonyOS鸿蒙Next中如何获取应用的包名和唯一标识呢?我们可以通过bundleManager.getBundleInfoForSelf 获取应用包名称和应用的唯一标识

aboutToAppear(): void {
    let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
    try {
      bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {

        hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));

      }).catch((err: BusinessError) => {

        hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);

      });
    } catch (err) {
      let message = (err as BusinessError).message;

      hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
    }
  }

更多关于 HarmonyOS鸿蒙Next中如何获取应用的包名和唯一标识的实战教程也可以访问 https://www.itying.com/category-93-b0.html

回到顶部