This article aims to deeply explore the technical details of the Huawei HarmonyOS Next system (as of API12 currently) in developing a multilingual e-commerce platform, and is summarized based on actual development practices. It mainly serves as a technical sharing and communication vehicle, and inevitably has omissions and errors. Colleagues are welcome to put forward valuable opinions and questions so that we can make progress together. This is original content, and any form of reproduction must indicate the source and the original author.
In the application development of the HarmonyOS Next system, permission application is a crucial link to ensure the legality, security, and complete functionality of the application. Correctly understanding and applying the system authorization and user authorization mechanisms can not only protect user data privacy but also improve the stability and user experience of the application. Today, let's explore in depth how to choose the appropriate application method according to the permission type and application requirements.1. Overview of HarmonyOS Next Permission Application
The HarmonyOS Next system conducts detailed classification management of application permissions to protect user data and system resources. Among them, system authorization and user authorization are the two main authorization methods, and they are respectively applicable to different types of permissions. Developers need to select the appropriate authorization method according to the specific functional requirements of the application. This is like when building a building, it is necessary to select the appropriate building materials and construction techniques according to the functional requirements of different areas to ensure the stability and safety of the building.
(1) System Authorization: The Convenience of Automatic Granting
System authorization, as the name implies, is a permission granting operation automatically completed by the system during the application installation process. This authorization method is applicable to those permissions that have little impact on the system or other applications and do not involve user sensitive information. For example, the permissions required for an application to obtain network information and query its own basic information usually adopt the system authorization method.
(2) User Authorization: User-centered Permission Granting
Unlike system authorization, user authorization pays more attention to the user's right to know and the right to choose. When an application needs to access the user's sensitive information or perform operations that may affect user privacy, such as using the camera, microphone, reading the address book, etc., it must obtain the user's explicit permission through the user authorization method. This ensures that the user always has control over their own data, just like setting up checkpoints in their own private territory, and only applications authorized by the user can enter and use the relevant resources.
2. Analysis of the System Authorization Process
(1) Permission Judgment and Application Preparation
Before performing system authorization, developers must first clarify the permissions required by the application and determine whether these permissions belong to the system authorization type. This requires developers to have an in-depth understanding of the permission system of HarmonyOS Next and be familiar with the classification and application scenarios of various permissions. It can be analogized to the route planning before sailing. Only by clarifying the destination and route can the smooth progress of sailing be ensured.
(2) The Process of System Automatically Granting Permissions
Once it is determined that the permissions required by the application are of the system authorization type, developers only need to correctly declare these permissions in the application's configuration file. When the user installs the application, the system will automatically identify and grant the corresponding permissions, and the entire process does not require the user to perform additional operations. This is like in an automated restaurant, the customer only needs to choose the dishes they want (declare permissions), and the automated system of the restaurant (HarmonyOS Next system) will automatically deliver the dishes to the customer (grant permissions).
(3) List of System-authorized Permissions
The following are some common system-authorized permissions and their descriptions:
| Permission Name | Permission Description |
|---|---|
| ohos.permission.USE_BLUETOOTH | Allows the application to view the configuration of Bluetooth. |
| ohos.permission.GET_BUNDLE_INFO | Allows querying the basic information of the application. |
| ohos.permission.PREPARE_APP_TERMINATE | Allows the application to perform custom pre-close actions before closing. |
| ohos.permission.PRINT | Allows the application to obtain the ability of the printing framework. |
| ohos.permission.DISCOVER_BLUETOOTH | Allows the application to configure local Bluetooth, search for remote devices and pair and connect with them. |3. Detailed Explanation of the User Authorization Process
(1) Declaring Permissions in the Configuration File
- Selection and Location of the Configuration File The first step in user authorization is to declare the required permissions in the application's configuration file. In a HarmonyOS Next project, the "module.json5" configuration file is usually used to declare permissions. This configuration file is like the "instruction manual" of the application, telling the system which permissions the application needs to run normally.
- Format and Specification of Permission Declaration In the "module.json5" file, permissions are declared through the "requestPermissions" field. Each permission declaration contains attributes such as "name" (permission name), "reason" (the reason for applying for the permission), and "usedScene" (the scene where the permission is used). For example:
{
"module": {
"requestPermissions":[
{
"name": "ohos.permission.CAMERA",
"reason": "$string:reason_camera",
"usedScene": {
"abilities": [
"MainAbility"
],
"when":"inuse"
}
}
]
}
}
Among them, "name" must be a valid permission name defined by the system, "reason" needs to explain to the user in a concise and clear language the reason for applying for the permission, and it must follow certain copywriting specifications, such as using straightforward, specific, and easy-to-understand complete short sentences, avoiding the passive voice, ending with a period, and ensuring that the string length is moderate to meet the needs of multi-language adaptation. "usedScene" is used to specify the scene where the permission is used,
Top comments (0)