方式一、使用应用上下文context获取。this.uiAbilityContext.abilityInfo.applicationInfo.codePath方式二:使用 @ohos.bundle.bundleManager 获取。导入 @ohos.bundle.bundleManager 模块,使用 bundleManager.getBundleInfoForSelf() 获取bundleInfo信息。使用 bundleInfo.appInfo.codePath 获取应用源文件路径。import bundleManager from '@ohos.bundle.bundleManager'; bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{ this.sourcePath = bundleInfo.appInfo.codePath; })
方式一、使用应用上下文context获取。
this.uiAbilityContext.abilityInfo.applicationInfo.codePath
方式二:使用
@ohos.bundle.bundleManager
获取。导入@ohos.bundle.bundleManager
模块,使用bundleManager.getBundleInfoForSelf()
获取bundleInfo信息。使用bundleInfo.appInfo.codePath
获取应用源文件路径。