Laval社区 【OpenHarmony应用开发】应用可读写权限目录

【OpenHarmony应用开发】应用可读写权限目录

以下内容对应OpenHarmony 3.1 Release其他版本可能出现问题,请注意3.1 Release中对应用访问data目录做了权限限制,但是提供了方法去访问应用自己的两个目录。cachefiles卸载应用会将所有信息删除import ability_featureAbility from ...

以下内容对应OpenHarmony 3.1 Release 其他版本可能出现问题,请注意

3.1 Release中对应用访问data目录做了权限限制,但是提供了方法去访问应用自己的两个目录。

  • cache
  • files

卸载应用会将所有信息删除

import ability_featureAbility from '@ohos.ability.featureAbility';

// 当前应用上下文
let context = ability_featureAbility.getContext();

async getApplicationDir(){
	let cacheDir: string
	let filesDir: string
	try{
		cacheDir = await context.getCacheDir()
		filesDir = await context.getFilesDir()
	}catch(e){
		console.log(e.message)	
	}

	return {
		cacheDir: cacheDir,
		filesDir: filesDir
	}
}

返回的路径信息(只允许使用这个路径去访问):

/data/storage/el2/base/haps/entry/cache /data/storage/el2/base/haps/entry/files

但这个路径并不是真实路径,真实路径信息对应:

/data/app/el2/100/base/com.ohos.myapplication/haps/entry/cache /data/app/el2/100/base/com.ohos.myapplication/haps/entry/files

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐

  • 浏览量 393
  • 收藏 0
  • 0

所有评论(0)

查看更多评论 
已为社区贡献9条内容