如何获取应用自身的源文件路径?

如何获取应用自身的源文件路径

阅读 282
1 个回答

方式一、使用应用上下文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; 
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进