[Daily HarmonyOS Knowledge] Web Audio Playback, Interface Call Failure, Bottom Banner Routing Issue, Rich Text Problem, Modifying Headers in onLoadIntercept
1. HarmonyOS web component plays audio without sound until the H5 page is touched?
Need to set mediaPlayGestureAccess(false)
.
Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5#ZH-CN_TOPIC_0000001847049744__mediaplaygestureaccess
2. HarmonyOS interface call fails?
The interface request is blocked with the error: Error: The input string contains unsupported characters
, but the interface works in Postman.
The error indicates unsupported characters in the input string. For Base64 decoding, refer to: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-util-V5.
This module provides common utility functions, including string encoding/decoding (TextEncoder, TextDecoder), rational number operations (RationalNumber8+), buffer management (LRUCache9+), range checking (ScopeHelper9+), Base64 encoding/decoding (Base64Helper9+), built-in object type checking (types8+), method instrumentation and replacement (Aspect11+), etc.
3. HarmonyOS bottom banner and subwindow routing issue?
How to show/hide the bottom banner and trigger routing (router.push…) in a subwindow?
How to make the target page route from the main window instead of the subwindow?
Reference code:
onWindowStageCreate(windowStage: window.WindowStage) {
windowStage.getMainWindow().then((windowObj) => {
windowObj.setWindowLayoutFullScreen(true);
windowObj.setWindowSystemBarEnable(['status'])
});
}
.onClick(()=>{
// Obtain windowStage via context first
(getContext() as common.UIAbilityContext).windowStage
// Get the main window
.getMainWindowSync().getUIContext()
// Get the routing stack
.getRouter()
// Push the page
.pushUrl({
"url":"pages/Page"
})
})
Reference link: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/application-window-stage-V5
- Window immersive capability: Controls system windows like the status bar and navigation bar to reduce their obtrusiveness, enhancing user experience. This capability only takes effect when the app's main window is in full-screen mode. Subwindows (pop-ups, floating windows, etc.) and the main window in freeform mode typically cannot use immersive capabilities.
- Floating window: A global floating window is a special app window that can remain visible in the foreground even when the main window and corresponding Ability go to the background. It can be used for continuing video playback in a small window or creating quick access points like floating balls for specific apps. Apps need to request corresponding permissions before creating floating windows.
4. How to implement capabilities similar to Html.fromHtml(pageContent)?
The RichText component does not support modifying background color, font color, font size, or dynamically changing content via properties and events. In such cases, using a Web component is recommended. Write the scenario in an H5 page and load it via the Web component.
Reference document: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5
5. How to modify the header of WebResourceRequest in HarmonyOS Web component's onLoadIntercept?
Modify the header using onInterceptRequest
. For specific usage, refer to: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5.
For setting headers via webview's loadUrl, refer to: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-webview-V5#loadurl.
Top comments (0)