## Can the app listen for the permission change after its permission is modified in Settings?
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
Third-party apps cannot listen for the permission change.
## Why is there no pop-up window displayed when an app applies for the **ohos.permission.LOCATION** permission?
Applicable to: OpenHarmony 3.2 Release (API version 9)
Applications developed using SDKs earlier than API version 9 can directly apply for the **ohos.permission.LOCATION** permission.
For the applications developed using the SDK of API version 9 or later, you need to apply for **ohos.permission.APPROXIMATELY_LOCATION** and then **ohos.permission.LOCATION**.
## What can I do to prevent the application from crashing when the application is started again after the user denies the permission requested?
Applicable to: OpenHarmony SDK 3.2 Beta5
**Possible Causes**
- If the permission required by a service is rejected by the user, the system directly returns the result and will no longer display a dialog box to request the permission.
- If related judgment is not performed after the permission is requested, the application will be rejected due to lack of the corresponding permission when accessing the target object under permission control, and terminated unexpectedly.
**Solution**
1. Before allowing an application to call an API protected by certain permission, verify whether the application has the permission. If the application has the permission, the application can call the API. Otherwise, a dialog box is dipslayed to ask user authorization.
2. If the user rejects to grant the permission, ensure that other functions irrelevant to this permission are not affected.
3. When this service is triggered again by the user or to implement a service function, on-screen message shall be provided to guide the user to grant the permission in **Settings**.
**References**
[Access Control (Permission) Overview](../security/accesstoken-overview.md)
## What are the differences between **extensionAbilities** and **requestPermissions** in the **module.json5** file?
Applicable to: OpenHarmony SDK 3.2 Beta5
-**requestPermissions**: specifies all the permissions required by an application for running. The permissions take effect only after being configured (declared) in the **module.json5** file.
-**extensionAbilitie.permissions**: specifies the permissions customized by the ExtensionAbility component. These permissions are required when an application needs to access the ExtensionAbility component. **extensionAbilitie.permissions** is used for permission verification only.
## What if a crash occurs when I obtain a string in JSON format from rawfile, convert the string into an object, and call the instance method?
Applicable to: OpenHarmony 3.2 Beta (API version 9)
**Symptom**
"jscrash happened in xxxxxxxxx" is displayed, and the crash log contains "Error message: Unexpected Object in JSON".
**Solution**
The prototype of the object obtained by parsing the string in JSON format is object. The prototype chain does not contain the instance method. Therefore, the object cannot be called.
To solve this problem, use either of the following methods:
1. Add the prototype to the parsed object.
2. Change the instance method to a static method and call it through the class name.
@@ -25,8 +25,6 @@ An error is reported when the **TRUNCATE TABLE** statement is used to clear tabl
The RDB store uses SQLite and does not support the **TRUNCATE TABLE** statement. To clear a table in an RDB store, use the **DELETE** statement, for example, **DELETE FROM sqlite\_sequence WHERE name = 'table\_name'**.
## What data types does an RDB store support?
Applicable to: OpenHarmony SDK 3.0 or later, API version 9 stage model
...
...
@@ -35,13 +33,43 @@ Applicable to: OpenHarmony SDK 3.0 or later, API version 9 stage model
An RDB store supports data of the number, string, and Boolean types. The number type supports data of the Double, Long, Float, Int, or Int64 type, with a maximum precision of 17 decimal digits.
## How do I save pixel map data to a database?
## How do I persist application data?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
**Solution**
You can use the **PersistentStorage** class to implement application data persistence. You can link the persistent data with specific tags to **AppStorage**, and invoke **AppStorage** APIs to access the persistent data. Persistent data is stored in a local XML file in **/data/app/el2/100/base/<bundleName\>/haps/<hapName\>/files/persistent\_storage**.
[Persistent Data Management\(OpenHarmony\)](../quick-start/arkts-persiststorage.md)
## How do I save pixel map data to a database?
Pixel map data fails to be stored.
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
...
...
@@ -55,6 +83,10 @@ Convert the pixel map data into an **ArrayBuffer** and save the **ArrayBuffer**
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
Problem of obtaining RDB store files.
**Solution**
The RDB store files are stored in **/data/app/el2/100/database/*Bundle_name*/entry/rdb/**. You can use the hdc command to copy the file from the directory and use a SQLite tool to open the file.
...
...
@@ -69,6 +101,10 @@ Example:
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
I do not know whether I need to design a lock mechanism for databases in development.
**Solution**
The distributed data service (DDS), RDB store, and preferences provided OpenHarmony have a lock mechanism. You do not need to bother with the lock mechanism during the development.
...
...
@@ -97,5 +133,26 @@ In API version 8, large text files cannot be saved in RDB stores.
**Solution**
In versions earlier than API version 9, the maximum length of a text file is 1024 bytes. If the text file exceeds 1024 bytes, it cannot be saved.
The limit on the text file size has been removed since API9 version.
## What if **undefined** is returned by **Preferences.get** after **Preferences.put()** is successfully called?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
Data is successfully saved using **preferences**, but fails to be obtained.
**Solution**
1. After **put()** is performed, use **flush()** to persist the data.
2. Wait until the **flush()** asynchronous operation is complete, and call **get()**.
## Can I specify the in-memory database mode when using an RDB store?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
RDB stores use SQLite. The default in-memory database mode is file, which cannot be modified.
## How do I obtain the path of system screenshots?
Applicable to: OpenHarmony 3.2 Beta5 (API version 9)
Applicable to: OpenHarmony 3.2 Beta5 (API version 9)
**Solution**
...
...
@@ -10,7 +10,7 @@ The screenshots are stored in **/storage/media/100/local/files/Pictures/Screensh
## How do I change the permissions on a directory to read/write on a device?
Applicable to: OpenHarmony 3.2 Beta5 (API version 9)
Applicable to: OpenHarmony 3.2 Beta5 (API version 9)
**Symptom**
...
...
@@ -19,3 +19,94 @@ When the hdc command is used to send a file to a device, "permission denied" is
**Solution**
Run the **hdc shell mount -o remount,rw /** command to grant the read/write permissions.
## What is the best way to create a file if the file to open does not exist?
Applicable to: OpenHarmony 3.2 (API version 9)
**Solution**
Use **fs.open(path: string, mode?: number)** with **mode** set to **fs.OpenMode.CREATE**. **fs.OpenMode.CREATE** creates a file if it does not exist.
## How do I solve the problem of garbled Chinese characters in a file?
Applicable to: OpenHarmony 3.2 (API version 9)
**Solution**
After the buffer data of the file content is read, use **TextDecoder** of @ohos.util to decode the file content.
```
let filePath = getContext(this).filesDir + "/test0.txt";
let stream = fs.createStreamSync(filePath, "r+");
let buffer = new ArrayBuffer(4096)
let readOut = stream.readSync(buffer);
let textDecoder = util.TextDecoder.create('utf-8', { ignoreBOM: true })
let readString = textDecoder.decodeWithStream(new Uint8Array(buffer), { stream: false });
console.log ("File content read: "+ readString);
```
## Why is an error reported when **fs.copyFile** is used to copy a **datashare://** file opened by **fs.open()**?
Applicable to: OpenHarmony 3.2 (API version 9)
**Solution**
**fs.copyFile** does not support URIs. You can use **fs.open()** to obtain the URI, obtain the file descriptor (FD) based on the URI, and then use **fs.copyFile** to copy the file based on the FD.
## How do I modify the specified content of a JSON file in the sandbox?
Applicable to: OpenHarmony 3.2 (API version 9)
**Solution**
Perform the following steps:
1. Use **fs.openSyn** to obtain the FD of the JSON file.
```
import fs from '@ohos.file.fs';
let sanFile = fs.open(basePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
let fd = sanFile.fd;
```
2. Use **fs.readSync** to read the file content.
```
let content = fs.readSync(basePath);
```
3. Modify the file content.
```
obj.name = 'new name';
```
4. Write the JSON file again.
```
fs.writeSync(file.fd, JSON.stringify(obj));
```
For more information, see [@ohos.file.fs](../reference/apis/js-apis-file-fs.md).
## What is the actual path corresponding to the file path obtained through the FileAccess module?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Solution**
The files are stored in the **/storage/media/100/local/files** directory. The specific file path varies with the file type and source. To obtain the actual file path, run the following command in the **/storage/media/100/local/files** directory:
**-name \[filename\]**
For more information, see [Uploading and Downloading an Application File](../file-management/app-file-upload-download.md).