| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 35 | 32 | ||
| entry/ | 06-May-2025 | - | 1,900 | 1,627 | ||
| hvigor/ | 06-May-2025 | - | 23 | 22 | ||
| screenshots/device/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 119 | 11 | 11 | |
| README_zh.md | D | 06-May-2025 | 5.4 KiB | 82 | 56 | |
| build-profile.json5 | D | 06-May-2025 | 1 KiB | 43 | 42 | |
| hvigorfile.ts | D | 06-May-2025 | 159 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 877 | 28 | 26 | |
| ohosTest.md | D | 06-May-2025 | 1 KiB | 9 | 7 |
README_zh.md
1# 为应用之间分享和文件访问提供统一的入口能力 2 3### 介绍 4 5本示例主要展示了沙箱文件分享相关的功能,使用 [@ohos.file.fileuri](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fileuri.md) 、[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md)、[@ohos.ability.wantConstant](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-wantConstant.md)、[@ohos.application.Want](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-want.md) 等接口,实现了获取文件uri、创建沙箱文件、提供want中操作want常数和解释Flags说、应用组件间的信息传递的功能。 6 7### 效果预览 8 9|首页|分享界面| 分享至picker后的编辑界面 | 10|--------------------------------|--------------------------------|--------------------------------| 11|||| 12 13使用说明: 14 151. 因本应用的功能依赖Picker应用,在使用本应用之前首先应安装[Picker](/code/SystemFeature/FileManagement/FileShare/Picker/README_zh.md)应用; 162. 在主界面,可以点击沙箱文件夹列出文件夹中的文件,同时也可以直接点击沙箱目录下的文件进入文件分享界面; 173. 点击沙箱文件,进入文件分享界面,点击分享图标,文件将以picker方式打开文件,点击编辑图标,文件进入可编辑模式,在textArea中输入内容,然后点击保存,文件内容更新,返回沙箱应用首页,文件修改成功。 18 19### 工程目录 20``` 21entry/src/main/ets/ 22|---Application 23|---Common 24| |---Common.ts // 公共方法 25| |---Utils.ts 26| |---Logger.ts // 日志工具 27|---MainAbility 28| |---EntryAbility.ts // Ability类 29|---fileFs 30| |---fileFs.ts // 创建沙箱文件 31|---pages 32| |---Index.ets // 首页 33| |---Show.ets // 文件分享页面 34``` 35### 具体实现 36 37* 增添文件、查找指定类型文件、获取文件uri、传递want信息启动ability的功能接口封装在fileFs.ts,源码参考:[fileFs.ts](/code/BasicFeature/FileManagement/FileShare/SandboxShare/entry/src/main/ets/fileFs/fileFs.ts) 38 39 * 使用fs.mkdirSync、fs.openSync、fs.writeSync、fs.readSync、fs.closeSync分别用来来创建文件夹、打开文件、写文件、读文件、关闭文件,接口参考:[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) 40 41 * 使用fileUri.getUriFromPath来获取文件uri,接口参考:[@ohos.file.fileuri](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fileuri.md) 42 43 * 分享文件至picker应用打开并编辑:在分享页面[show.ets](/code/BasicFeature/FileManagement/FileShare/SandboxShare/entry/src/main/ets/pages/Show.ets) 44 45 调用 implicitStartAbility 方法传递want参数启动新的ability,接口参考:[@ohos.ability.wantConstant](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-wantConstant.md)、[@ohos.application.Want](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-want.md) 46 47 48### 相关权限 49 50| 权限名 | 权限说明 | 级别 | 51| ------------------------------------------ | ---------------------------------------- | ------------ | 52| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | 允许查询应用的基本信息和其他敏感信息。 | system_basic | 53| ohos.permission.MEDIA_LOCATION | 允许应用访问用户媒体文件中的地理位置信息 | normal | 54| ohos.permission.READ_MEDIA | 允许应用读取用户外部存储中的媒体文件信息 | normal | 55| ohos.permission.WRITE_MEDIA | 允许应用读写用户外部存储中的媒体文件信息 | normal | 56 57### 依赖 58 59本应用需要依赖[Picker](/code/SystemFeature/FileManagement/FileShare/Picker/README_zh.md)应用,沙箱文件需分享至Picker应用打开并编辑保存 60 61### 约束与限制 62 631.本示例仅支持标准系统上运行,支持设备:RK3568; 64 652.本示例为Stage模型,仅支持API9版本SDK,版本号:3.2.12.2,镜像版本号:OpenHarmony 4.0.9.1。 66 673.本示例需要使用DevEco Studio 3.1 Release (Build Version: 3.1.0.500, built on April 28, 2023)及以上版本才可编译运行。 68 694.本示例涉及部分接口需要配置系统应用签名,可以参考[特殊权限配置方法](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/hapsigntool-overview.md) ,把配置文件中的“apl”字段信息改为“system_basic”。 70 71### 下载 72 73如需单独下载本工程,执行如下命令: 74``` 75git init 76git config core.sparsecheckout true 77echo code/BasicFeature/FileManagement/FileShare/SandboxShare > .git/info/sparse-checkout 78git remote add origin https://gitee.com/openharmony/applications_app_samples.git 79git pull origin master 80 81``` 82