openharmony 鸿蒙 share-app-file-configuration

2026-08-25 浏览 (1)

Configuring the Application Shared Directory

From API version 23, shared directory configuration is supported. In the application file sharing scenario, you can configure the shared directory scope to prevent sensitive data disclosure.

How to Develop

  1. Add the shareFiles tag to the module tag in the application module-level configuration file src/main/module.json5 to restrict permissions for sandbox shared directories. If no shared directory is configured, the application is allowed to share files in its own sandbox by default.

    shareFiles tag

    {
      "module": {
        // ...
        "shareFiles": "$profile:share_files", // Resource configuration, which points to the configuration file share_files.json defined in the profile.
        // ...
      }
    }
    
  2. Define the configuration file share_files.json under resources/base/profile in the development view to specify the permission information for all shared paths of the current module.

    The file name share_files can be changed to any valid file name, but must be the same as the file name configured in the shareFiles tag.

    Description of the share_files tag

PropertyDescriptionData TypeMandatory
scopesSharing scope. For details, see the description of the scopes tag.Object arrayNo

Description of the scopes tag

PropertyDescriptionData TypeMandatory
pathShared path. Currently, only the el2 directory is supported. It is unique in scopes. The options are as follows:
- /base/files
- /base/preferences
- /base/haps
stringMandatory when scopes exists.
permissionShared path permission. The options are as follows:
- r: read-only.
- r+w: read and write.
stringMandatory when scopes exists.

NOTE

If the configuration is modified during an application update, the new configuration takes effect for management, and temporary shared file permissions remain unaffected.

Example of share_files.json:

{
  "share_files": {
    "scopes": [
      {
        "path": "/base/files",
        "permission": "r+w"
      }
    ]
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 native-fileshare-guidelines

openharmony 鸿蒙 manage-external-storage-sys

openharmony 鸿蒙 file-persistPermission

openharmony 鸿蒙 app-file-backup-extension

openharmony 鸿蒙 request-dir-permission

openharmony 鸿蒙 user-file-overview

openharmony 鸿蒙 select-user-file

openharmony 鸿蒙 app-file-backup-overview

openharmony 鸿蒙 file-access-across-devices

openharmony 鸿蒙 share-app-file

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/MOE9EEma