未验证 提交 79380e91 编写于 作者: O openharmony_ci 提交者: Gitee

!18369 翻译完成:17559+17536 faqs 文件夹更新

Merge pull request !18369 from wusongqing/TR17559
# FAQs
- [Ability Framework Development](faqs-ability.md)
- [Resource Management Development](faqs-globalization.md)
- [Ability Development](faqs-ability.md)
- [Bundle Management Development](faqs-bundle-management.md)
- [Resource Manager Development](faqs-globalization.md)
- [Common Event and Notification Development](faqs-event-notification.md)
- [Graphics and Image Development](faqs-graphics.md)
- [Data Management Development](faqs-distributed-data-management.md)
- [Graphics Development](faqs-graphics.md)
- [Window Management Development](faqs-window-manager.md)
- [Multimedia Development](faqs-multimedia.md)
- [Basic Security Capability Development](faqs-security.md)
- [Application Access Control Development](faqs-ability-access-control.md)
- [Ability 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)
- [DFX Development](faqs-dfx.md)
- [Pan-Sensor Development](faqs-sensor.md)
- [Startup Development](faqs-startup.md)
- [Usage of Third- and Fourth-Party Libraries](faqs-third-fourth-party-library.md)
\ No newline at end of file
- [Distributed Device Development](faqs-distributed-device-profile.md)
- [Usage of Third- and Fourth-Party Libraries](faqs-third-fourth-party-library.md)
# Bundle Management Development
## How do I determine whether an application is a system application?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
Use **bundleManager.getApplicationInfo** (available only for system applications) to obtain application information, and check the value of **systemApp** in the information. The application is a system application if the value is **true**.
**Reference**
[bundleManager](../reference/apis/js-apis-bundleManager.md)
## How do I obtain the version code and version name of an application?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
Use **bundleManager.getBundleInfoForSelf\(\)** to obtain the bundle information, which contains the version code (specified by **BundleInfo.versionCode**) and version name (specified by **BundleInfo.versionName**) .
**Example**
```
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
const versionCode = data.versionCode;
const versionName = data.versionName;
hilog.info(0x0000, 'testTag', `successfully. versionCode: ${versionCode}, versionName: ${versionName}`);
}).catch(err => {
hilog.error(0x0000, 'testTag', 'failed. Cause: %{public}s', err.message);
});
} catch (err) {
hilog.error(0x0000, 'testTag', 'failed: %{public}s', err.message);
}
```
**Reference**
[getBundleInfoForSelf](../reference/apis/js-apis-bundleManager.md#bundlemanagergetbundleinfoforself)
## How do I obtain the bundle name of the current application?
Applicable to: OpenHarmony 3.2 Beta5 (API version 9)
**Solution**
Obtain the bundle name from **UIAbilityContext.abilityInfo.bundleName**.
**Example**
```
import common from '@ohos.app.ability.common';
const context = getContext(this) as common.UIAbilityContext
console.log(`bundleName: ${context.abilityInfo.bundleName}`)
```
**Reference**
[UIAbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontext) and [AbilityInfo](../reference/apis/js-apis-bundleManager-abilityInfo.md#abilityinfo)
## How do I obtain the application version number, version name, and screen resolution?
Applicable to: OpenHarmony 3.2 Beta5
**Solution**
1. Obtain the bundle information from the **@ohos.bundle.bundleManager** module.
The bundle information contains the application version number and version name.
```
import bundleManager from '@ohos.bundle.bundleManager';
...
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{
let versionName = bundleInfo.versionName; // Application version name.
let versionNo = bundleInfo.versionCode; // Application version number.
}).catch((error)=>{
console.error("get bundleInfo failed,error is "+error)
})
```
2. Obtain **screenDensity** from the **@ohos.app.ability.Configuration** module. **screenDensity** contains the screen resolution information.
```
import common from '@ohos.app.ability.common';
...
let context = getContext(this) as common.UIAbilityContext;
let screenDensity = context.config.screenDensity;
```
## How do I obtain the source file path of the current application?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
- Method 1: Use the application context to obtain the source file path.
```
this.uiAbilityContext.abilityInfo.applicationInfo.codePath
```
- Method 2: Use **@ohos.bundle.bundleManager** to obtain the source file path.
1. Import the **@ohos.bundle.bundleManager** module and use **bundleManager.getBundleInfoForSelf\(\)** to obtain the bundle information.
2. Obtain the source file path from **bundleInfo.appInfo.codePath**.
```
import bundleManager from '@ohos.bundle.bundleManager';
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{
this.sourcePath = bundleInfo.appInfo.codePath;
})
```
## Can I obtain the HAP information of other applications from the current application?
Applicable to: OpenHarmony 3.2 Beta (API version 9)
According to the OpenHarmony security design specifications, the SDK does not provide APIs for third-party applications to obtain bundle information (including but not limited to the application name and version number) of other applications.
# Bundle Management Development
## How do I obtain the version code and version name of an application?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Use **bundle.getBundleInfo()** to obtain the bundle information, which contains the version code and version name.
Reference: [Bundle](../reference/apis/js-apis-Bundle.md#bundlegetbundleinfo)
## How do I obtain the bundle name of an application?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Obtain the bundle name through **context.abilityInfo.bundleName**.
Reference: [AbilityInfo](../reference/apis/js-apis-bundle-AbilityInfo.md)
## How do I obtain an application icon?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Use **bundle.getAbilityIcon** to obtain the application icon. To use this API, you must configure the permission **ohos.permission.GET_BUNDLE_INFO**.
Reference: [Bundle](../reference/apis/js-apis-Bundle.md#bundlegetbundleinfo)
## How do I determine whether an application is a system application?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Use **bundle.getApplicationInfo** to obtain the application information, and then check the value of **systemApp** in the information. The application is a system application if the value is **true**.
# Distributed Device Development
## How do I view the IMEI of an OpenHarmony device?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
Obtain the device IMEI from the **HUKS\_TAG\_ATTESTATION\_ID\_IMEI** parameter of the **HuksTag** API. [Reference](../reference/apis/js-apis-huks.md)
# Graphics and Image Development
# Graphics Development
## Why do the isStatusBarLightIcon and isNavigationBarLightIcon attributes not take effect when window.setSystemBarProperties() is called?
## How do I obtain the DPI of a device?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Applicable to: OpenHarmony 3.2 Beta5 (API version 9, stage model)
In effect, the **isStatusBarLightIcon** and **isNavigationBarLightIcon** attributes turn the font white when set to **true**. If **statusBarContentColor** is also set in **window.setSystemBarProperties()**, the **isStatusBarLightIcon** attribute does not take effect. Similarly, if **navigationBarContentColor** is set, the **isNavigationBarLightIcon** attribute does not take effect.
**Solution**
## How do I set the style of the system bar?
Import the **@ohos.display** module and call the **getDefaultDisplaySync\(\)** API.
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
**Example**
Import the **\@ohos.window** module, and call **window.setSystemBarProperties()**.
```
import display from '@ohos.display';
let displayClass = null;
try {
displayClass = display.getDefaultDisplaySync();
console.info('Test densityDPI:' + JSON.stringify(displayClass.densityDPI));
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
```
## How do I hide the status bar to get the immersive effect?
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9
1. Use the **onWindowStageCreate** to obtain a **windowClass** object.
```ts
onWindowStageCreate(windowStage) {
// When the main window is created, set the main page for this ability.
console.log("[Demo] EntryAbility onWindowStageCreate")
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window.')
return;
}
// Obtain a windowClass object.
globalThis.windowClass = data;
})
}
```
2. Enable the full-screen mode for the window and hide the status bar.
```ts
globalThis.windowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});
```
Applicable to: OpenHarmony 3.2 Beta5 (API version 9, stage model)
**Solution**
1. Use **onWindowStageCreate** to obtain a **windowClass** object.
```
onWindowStageCreate(windowStage) {
// When the main window is created, set the main page for this ability.
console.log("[Demo] MainAbility onWindowStageCreate")
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window.')
return;
}
// Obtain a windowClass object.
globalThis.windowClass = data;
})
}
```
2. Enable the full-screen mode for the window and hide the status bar.
```
globalThis.windowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});
```
## How do I obtain the window width and height?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Applicable to: OpenHarmony SDK 3.2 Beta5 (API version 9, stage model)
Use **window.getProperties()** to obtain the window properties. The **windowRect** field in the properties specifies the window width and height.
**Solution**
Example:
Import the **@ohos.window** module, obtain a **Window** object, and use **getWindowProperties\(\)** of the object to obtain the window properties. The **windowRect** field in the properties specifies the window width and height.
**Example**
```ts
let promise = windowClass.getProperties();
promise.then((data)=> {
console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data.windowRect));
}).catch((err)=>{
console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
});
```
## How do I set the color of the system bar?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Refer to the following code:
```ts
window.getTopWindow(globalThis.mainContext).then(win => {
var systemBarProperties = {
statusBarColor: '#19B6FF', // Set the background color of the status bar.
navigationBarColor: '#19B6FF', // Set the background color of the navigation bar.
isStatusBarLightIcon: false, // Set the icon on the status bar not to be highlighted.
isNavigationBarLightIcon: true, // Set the icon on the navigation bar to be highlighted.
statusBarContentColor: '#0D0500', // Set the text color of the status bar.
navigationBarContentColor: '#FFA500' // Set the text color of the navigation bar.
};
win.setSystemBarProperties(systemBarProperties).catch(err => {
INDEX_LOGGER.info(`set System Bar Properties failed:${err}`)
})
})
.catch(err => {
INDEX_LOGGER.info(`get top window failed:${err}`)
})
import window from '@ohos.window';
let windowClass = null;
try {
let promise = window.getLastWindow(this.context);
promise.then((data)=> {
// Obtain a Window object.
windowClass = data;
try {
// Obtain the window properties.
let properties = windowClass.getWindowProperties();
let rect = properties.windowRect;
// rect.width: window width; rect.height: window height.
} catch (exception) {
console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception));
}
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});} catch (exception) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
}
```
# Multimedia Development
## How do I obtain the frame data of a camera when using the XComponent to display the preview output stream of the camera?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Symptom**
Currently, the API does not support real-time preview of the camera frame data. To obtain the frame data, you must bind an action, for example, photographing.
**Solution**
Create a dual-channel preview to obtain the frame data.
1. Use the XComponent to create a preview stream.
```
// Obtain a PreviewOutput instance.
const surfaceId = globalThis.mxXComponentController.getXComponentSurfaceld();
this.mPreviewOutput = await Camera.createPreviewOutput(surfaceld) ;
```
2. Use imageReceiver to listen for image information.
```
// Add dual-channel preview.
const fullWidth = this.mFullScreenSize.width;
const fullHeight = this.mFullScreenSize.height;
const imageReceiver = await image.createImageReceiver(fullwidth, fullHeight,
formatImage, capacityImage) ;
const photoSurfaceId = await imageReceiver.getReceivingSurfaceld();
this.mPreviewOutputDouble = await Camera.createPreviewOutput ( photoSurfaceld)
```
## How do I obtain the preview image of the front camera?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Solution**
1. Use the **@ohos.multimedia.camera** module to obtain the physical camera information.
```
let cameraManager = await camera.getCameraManager(context);
let camerasInfo = await cameraManager.getSupportedCameras();
let cameraDevice = this.camerasInfo[0];
```
2. Create and start the input stream channel of the physical camera.
```
let cameraInput = await cameraManager.createCameraInput(cameraDevice);
await this.cameraInput.open();
```
3. Obtain the output formats supported by the camera, and create a preview output channel based on the surface ID provided by the XComponent.
```
let outputCapability = await this.cameraManager.getSupportedOutputCapability(cameraDevice);
let previewProfile = this.outputCapability.previewProfiles[0];
let previewOutput = await cameraManager.createPreviewOutput(previewProfile, previewId);
```
4. Create a camera session, add the camera input stream and preview output stream to the session, and start the session. The preview image is displayed on the XComponent.
```
let captureSession = await cameraManager.createCaptureSession();
await captureSession.beginConfig();
await captureSession.addInput(cameraInput);
await captureSession.addOutput(previewOutput);
await this.captureSession.commitConfig()
await this.captureSession.start();
```
## How do I set the camera focal length?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Solution**
1. Check whether the camera is a front camera. A front camera does not support focal length setting.
2. Use **captureSession.getZoomRatioRange\(\)** to obtain the focal length range supported by the device.
3. Check whether the target focal length is within the range obtained. If yes, call **captureSession.setZoomRatio\(\)** to set the focal length.
## How do I play music in the background?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Symptom**
Music cannot be played in the background.
**Solution**
**AVSession** controls media playback. When a third-party application switches to the background or encounters a screen lock event, media playback is forcibly paused and the application is unaware of the pause. To enable the application to continue the playback in the background, request a continuous task and access the AVSession capability, which allows Control Panel to control the playback behavior of third-party applications.
**Reference**
[Continuous Task Development](../task-management/continuous-task-dev-guide.md)
[AVSession Development](../media/using-avsession-developer.md)
## What should I do when multiple video components cannot be used for playback?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Symptom**
A large number of video components are created. They cannot play media normally or even crash.
**Solution**
A maximum of 13 media player instances can be created.
## How do I invoke the image library directly?
Applicable to: OpenHarmony 3.2 (API version 9, stage model)
**Solution**
```
let want = {
bundleName: 'com.ohos.photos',
abilityName: 'com.ohos.photos.MainAbility',
parameters: {
uri: 'detail'
}
};
let context = getContext(this) as common.UIAbilityContext;
context.startAbility(want);
```
# Pan-Sensor Development
## Are the APIs used for obtaining PPG and ECG sensor data open to individual developers?
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
Data collected by the PPG and ECG sensors of wearable devices is personal privacy data. Therefore, relative APIs are not open to individual developers.
# Usage of Third- and Fourth-Party Libraries
## What does the following error message mean: "Stage model module... does not support including OpenHarmony npm packages or modules in FA model. OpenHarmony build tasks will not be executed, and OpenHarmony resources will not be packed."
## How do I obtain available third-party libraries?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
The third- and fourth-party libraries are not yet compatible with the stage model of API version 9 and cannot be used.
The three-party and four-party libraries that can be obtained through ohpm are summarized in the [OpenHarmony-TPC/tpc_resource repository](https://gitee.com/openharmony-tpc/tpc_resource). You can access this repository, and find the desired component based on the directory index.
## Can I transfer project-level dependencies?
## Which third-party libraries are related to network requests?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
For example, if project A depends on project B and project B depends on project C, can project A directly use the APIs provided by project C?
The following third-party libraries are related to network requests: [Axios](https://gitee.com/openharmony-sig/axios), httpclient, and okdownload. For details, see the [OpenHarmony-TPC/tpc_resource repository](https://gitee.com/openharmony-tpc/tpc_resource).
No. Project A cannot directly use the APIs provided by project C. The project packing tool NPM does not support dependency transfer. To use the APIs provided by project C, you can add the dependency of project C to project A.
## How do I use ohpm to import third- and fourth-party libraries?
## How do I obtain available third-party libraries?
Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
Applicable to: OpenHarmony SDK 3.2.6.5, stage model of API version 9
**Solution**
For details, see [Third-Party Components That Can Be Directly Used on OpenHarmony](https://gitee.com/openharmony-sig/third_party_app_libs).
- Method 1:
1. Open the **Terminal** window and run the following command to go to the **entry** directory:
## Which third-party libraries are related to network requests?
```
cd entry
```
2. Run the following command to install a third-party library, for example, **dayjs**:
```
ohpm install dayjs
```
3. Add the following statement in the .js file to import the third-party library:
```
import dayjs from 'dayjs';
```
Applicable to: OpenHarmony SDK 3.2.6.5, stage model of API version 9
The [Axios](https://gitee.com/openharmony-sig/axios) library is related to network requests.
## How do I use NPM to import third- and fourth-party libraries?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
- Method 1:
1. Open the **Terminal** window and run the following command to go to the **entry** directory:
```
cd entry
```
2. Run the following command to install a third-party package, for example, **dayjs**:
```
npm install dayjs --save
```
3. Add the following statement in the .js file to import the package:
```
import dayjs from 'dayjs';
```
- Method 2:
1. Enter the **entry** directory of the project and open the **package.json** file.
2. Write the third-party NPM package to be installed (for example, **dayjs**) in the **package.json** file.
```
{
"dependencies": {
"dayjs": "^1.10.4",
- Method 2:
1. Enter the **entry** directory of the project and open the **oh-package.json5** file.
2. Write the third-party library to be installed (for example, **dayjs**) in the **oh-package.json5** file.
```
{
"dependencies": {
"dayjs": "^1.10.4",
}
}
}
```
3. Open the **Terminal** window and run the following command to go to the **entry** directory:
```
cd entry
```
4. Run the following command to install NPM:
```
npm install
```
5. Add the following statement in the .js file to import the package:
```
import dayjs from 'dayjs';
```
```
3. Open the **Terminal** window and run the following command to go to the **entry** directory:
```
cd entry
```
4. Run the following command to install the third-party library:
```
ohpm install
```
5. Add the following statement in the .js file to import the third-party library:
```
import dayjs from 'dayjs';
```
# Window Management Development
## How do I obtain the height of the status bar and navigation bar?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
Before the window content is loaded, enable listening for the **systemAvoidAreaChange** event.
**Example**
```
// MainAbility.ts
import window from '@ohos.window';
/**
* Set the immersive window and obtain the height of the status bar and navigation bar.
* @param mainWindow Indicates the main window.
*/
async function enterImmersion(mainWindow: window.Window) {
mainWindow.on("systemBarTintChange", (data) => {
let avoidAreaRect = data.regionTint[0].region; // data.regionTint is an array that contains the rectangle coordinates of the status bar and navigation bar.
})
await mainWindow.setFullScreen(true)
await mainWindow.setSystemBarEnable(["status", "navigation"])
await mainWindow.systemBarProperties({
navigationBarColor: "#00000000",
statusBarColor: "#00000000",
navigationBarContentColor: "#FF0000",
statusBarContentColor: "#FF0000"
})
}
export default class MainAbility extends Ability {
// Do something.
async onWindowStageCreate(windowStage: window.WindowStage) {
let mainWindow = await windowStage.getMainWindow()
await enterImmersion(mainWindow)
windowStage.loadContent('pages/index')
}
// Do something.
}
```
## How do I hide the status bar on the top of an application?
Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
**Solution**
Use **setWindowSystemBarEnable** in the **onWindowStageCreate** lifecycle callback of UIAbility.
**Example**
```
onWindowStageCreate(windowStage){
windowStage.getMainWindowSync().setWindowSystemBarEnable([])
......
}
```
**Reference**
[Window](../reference/apis/js-apis-window.md)
......@@ -1534,12 +1534,20 @@
- FAQs
- [Full SDK Compilation Guide](quick-start/full-sdk-compile-guide.md)
- [Guide to Switching to Full SDK](quick-start/full-sdk-switch-guide.md)
- [Ability Framework Development](faqs/faqs-ability.md)
- [Resource Management Development](faqs/faqs-globalization.md)
- [Ability Development](faqs/faqs-ability.md)
- [Bundle Management Development](faqs/faqs-bundle-management.md)
- [Resource Manager Development](faqs/faqs-globalization.md)
- [Common Event and Notification Development](faqs/faqs-event-notification.md)
- [Graphics and Image Development](faqs/faqs-graphics.md)
- [Graphics Development](faqs/faqs-graphics.md)
- [Window Management Development](faqs/faqs-window-manager.md)
- [Multimedia Development](faqs/faqs-multimedia.md)
- [Basic Security Capability Development](faqs/faqs-security.md)
- [Ability Access Control Development](faqs/faqs-ability-access-control.md)
- [Data Management Development](faqs/faqs-distributed-data-management.md)
- [File Management Development](faqs/faqs-file-management.md)
- [Network Management Development](faqs/faqs-network-management.md)
- [DFX Development](faqs/faqs-dfx.md)
- [Pan-Sensor Development](faqs/faqs-sensor.md)
- [Startup Development](faqs/faqs-startup.md)
- [Usage of Third- and Fourth-Party Libraries](faqs/faqs-third-fourth-party-library.md)
\ No newline at end of file
- [Distributed Device Development](faqs/faqs-distributed-device-profile.md)
- [Usage of Third- and Fourth-Party Libraries](faqs/faqs-third-fourth-party-library.md)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册