未验证 提交 657fe77c 编写于 作者: O openharmony_ci 提交者: Gitee

!18156 [翻译完成】PR17535

Merge pull request !18156 from Annie_wang/PR17535
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
- [ArkUI (JavaScript) Development](faqs-ui-js.md) - [ArkUI (JavaScript) Development](faqs-ui-js.md)
- [Common Event and Notification Development](faqs-event-notification.md) - [Common Event and Notification Development](faqs-event-notification.md)
- [Graphics and Image Development](faqs-graphics.md) - [Graphics and Image Development](faqs-graphics.md)
- [File Management Development](faqs-file-management.md)
- [Media Development](faqs-media.md) - [Media Development](faqs-media.md)
- [Basic Security Capability Development](faqs-security.md)
- [Application Access Control Development](faqs-ability-access-control.md)
- [Data Management Development](faqs-distributed-data-management.md)
- [File Management Development](faqs-file-management.md)
- [Network Management Development](faqs-network-management.md) - [Network Management Development](faqs-network-management.md)
- [DFX Development](faqs-dfx.md) - [DFX Development](faqs-dfx.md)
- [Native API Usage](faqs-native.md) - [Native API Usage](faqs-native.md)
......
# Application Access Control Development
## 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.
# Data Management Development
## How do I encrypt an RDB store?
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
**Solution**
To encrypt an RDB store, set **encrypt** in **StoreConfig** to **true** when creating the RDB store.
**Reference**
[RDB Store](../reference/apis/js-apis-data-relationalStore.md#storeconfig)
## What if I failed to clear a table in an RDB store using TRUNCATE TABLE?
Applicable to: OpenHarmony SDK 3.2.9.2 (API version 9)
**Symptom**
An error is reported when the **TRUNCATE TABLE** statement is used to clear table data.
**Solution**
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
**Solution**
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?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
Pixel map data fails to be stored.
**Solution**
Convert the pixel map data into an **ArrayBuffer** and save the **ArrayBuffer** to your database.
**Reference**
[readPixelsToBuffer](../reference/apis/js-apis-image.md#readpixelstobuffer7-1)
## How do I obtain RDB store files?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**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.
Example:
```
hdc file recv /data/app/el2/100/database/<bundleName>/entry/db/<tableName> ./<path>
```
## Do the OpenHarmony databases have a lock mechanism?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**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.
## What if I failed to use get() to obtain the data saved by @ohos.data.storage put()?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
After @ohos.data.storage **put()** is called to save data, **get()** is called to obtain the data. However, the data fails to be obtained.
**Solution**
The **put()** method provided by **@ohos.data.storage** saves data in the memory. When the application exits, the data in the memory will be cleared. If you want to persist the data, you need to call **flush()** or **flushSync()** after **put()**. After data is persisted, you can use **get()** to obtain the data after the application is restarted.
## What if a large text file fails to be saved in an RDB store?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Symptom**
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.
# File Management Development # File Management Development
## Does fileio.rmdir Delete Files Recursively? ## How do I obtain the path of system screenshots?
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9 Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
Yes. **fileio.rmdir** deletes files recursively. **Solution**
## How Do I Create a File That Does Not Exist? The screenshots are stored in **/storage/media/100/local/files/Pictures/Screenshots/**.
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9 ## How do I change the permissions on a directory to read/write on a device?
You can use **fileio.open(filePath, 0o100, 0o666)**. The second parameter **0o100** means to create a file if it does not exist. The third parameter **mode** must also be specified. Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
## What If "call fail callback fail, code: 202, data: json arguments illegal" Is Displayed? **Symptom**
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9 When the hdc command is used to send a file to a device, "permission denied" is displayed.
When the **fileio** module is used to copy files, the file path cannot start with "file:///". **Solution**
## How Do I Read Files Outside the App Sandbox? Run the **hdc shell mount -o remount,rw /** command to grant the read/write permissions.
Applicable to: OpenHarmony SDK 3.2.6.5, stage model of API version 9
If the input parameter of the **fileio** API is **path**, only the sandbox directory of the current app obtained from the context can be accessed. To access data in other directories such as the user data, images, and videos, open the file as the data owner and operate with the file descriptor (FD) returned.
For example, to read or write a file in Media Library, perform the following steps:
1. Use **getFileAssets()** to obtain the **fileAsset** object.
2. Use **fileAsset.open()** to obtain the FD.
3. Use the obtained FD as the **fileIo** API parameter to read and write the file.
## What If the File Contains Garbled Characters?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Read the file content from the buffer, and decode the file content using **util.TextDecoder**.
Example:
```
import util from '@ohos.util'
async function readFile(path) {
let stream = fileio.createStreamSync(path, "r+");
let readOut = await stream.read(new ArrayBuffer(4096));
let textDecoder = new util.TextDecoder("utf-8", { ignoreBOM: true });
let buffer = new Uint8Array(readOut.buffer)
let readString = textDecoder.decode(buffer, { stream: false });
console.log ("[Demo] File content read: "+ readString);
}
```
## What Should I Do If There Is No Return Value or Error Captured After getAlbums Is Called?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
The **ohos.permission.READ_MEDIA** is required for using **getAlbums()**. In addition, this permission needs user authorization. For details, see [OpenHarmony Permission List](../security/permission-list.md).
1. Configure the required permission in the **module.json5** file.
```
"requestPermissions": [
{
"name": "ohos.permission.READ_MEDIA"
}
]
```
2. Add the code for user authorization before the **MainAbility.ts -> onWindowStageCreate** page is loaded.
```
import abilityAccessCtrl from '@ohos.abilityAccessCtrl.d.ts';
private requestPermissions() {
let permissionList: Array<string> = [
"ohos.permission.READ_MEDIA"
];
let atManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(this.context, permissionList)
.then(data => {
console.info(`request permission data result = ${data.authResults}`)
})
.catch(err => {
console.error(`fail to request permission error:${err}`)
})
}
```
## What Do I Do If the App Crashes When FetchFileResult() Is Called Multiple Times?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Each time after the **FetchFileResult** object is called, call **FetchFileResult.close()** to release and invalidate the **FetchFileResult** object .
## What If An Error Is Reported by IDE When mediaLibrary.getMediaLibrary() Is Called in the Stage Model?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
In the stage model, use **mediaLibrary.getMediaLibrary(context: Context)** to obtain the media library instance.
## How Do I Sort the Data Returned by mediaLibrary.getFileAssets()?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Use the **order** attribute in **[MediaFetchOptions](../reference/apis/js-apis-medialibrary.md#mediafetchoptions7)** to sort the data returned.
# Basic Security Capability Development
## What is the maximum number of bytes that can be encrypted at a time in AES GCM mode in HUKS?
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
**Solution**
In HUKS, a maximum of 64 bytes can be encrypted at a time in AES GCM mode.
**Example**
```
/* Encrypt the key. */
await huks.init(srcKeyAlias, encryptOptions).then((data) => {
console.info(`test init data: ${JSON.stringify(data)}`);
handle = data.handle;
}).catch((err) => {
console.info('test init err information: ' + JSON.stringify(err));
});
encryptOptions.inData = aesCipherStringToUint8Array(cipherInData.slice (0,64)); // Take 64 bytes.
await huks.update(handle, encryptOptions).then(async (data) => {
console.info(`test update data ${JSON.stringify(data)}`);
encryptUpdateResult = Array.from(data.outData);
}).catch((err) => {
console.info('test update err information: ' + err);
});
encryptOptions.inData = aesCipherStringToUint8Array(cipherInData.slice (64,80)); // Remaining data
```
## What if garbled characters are returned by **digest()** of **Md** in Crypto framework?
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
**Symptom**
In the CryptoFramework, garbled characters are returned by **digest()** of **Md**.
**Solution**
The DataBlob returned by **digest()** is of the Uint8Array type and needs to be converted into a hexadecimal string before being printed. You can use the online MD5 encryption tool to verify the result.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册