From 37282c338698dcc56a2d04670c8413f3260b86e0 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Wed, 9 Jul 2025 10:12:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/utils/LiveView.ets | 8 ++++---- entry/src/main/ets/utils/LiveViewUtil.ets | 15 ++++++++++----- entry/src/main/ets/view/TrafficInfoView.ets | 4 ++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6e0b5f7..0b0ac67 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ 1.本示例仅支持标准系统上运行,支持设备:华为手机; -2.HarmonyOS系统:HarmonyOS 5.0.0 Developer Release及以上; +2.HarmonyOS系统:HarmonyOS 5.0.0 Release及以上; -3.DevEco Studio版本:DevEco Studio 5.0.0 Developer Release及以上; +3.DevEco Studio版本:DevEco Studio 5.0.0 Release及以上; -4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Developer Release SDK及以上。 \ No newline at end of file +4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 076f342..78957cc 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -97,7 +97,7 @@ export struct LiveViewLockScreenPage { }); aboutToAppear(): void { - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.customDialogController?.open(); } diff --git a/entry/src/main/ets/utils/LiveView.ets b/entry/src/main/ets/utils/LiveView.ets index fda43bd..4ae8213 100644 --- a/entry/src/main/ets/utils/LiveView.ets +++ b/entry/src/main/ets/utils/LiveView.ets @@ -30,18 +30,18 @@ const TAG: string = '[LiveView]'; export class LiveView { // Singleton pattern implementation private static instance: LiveView; - private context: Context | undefined; + private context: Context; private liveViewController: LiveViewUtil; private updateInterval: number | undefined; // Private constructor for singleton pattern - private constructor(context: Context | undefined) { + private constructor(context: Context) { this.context = context; - this.liveViewController = new LiveViewUtil(); + this.liveViewController = new LiveViewUtil(context); } // Singleton accessor method - public static getInstance(context: Context | undefined): LiveView { + public static getInstance(context: Context): LiveView { // Lazy initialization of the singleton instance if (!LiveView.instance) { LiveView.instance = new LiveView(context); diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index 1616ebb..eb060cf 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { application, Want, wantAgent } from '@kit.AbilityKit'; +import { Want, wantAgent } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; // [Start createLiveView] import { liveViewManager } from '@kit.LiveViewKit'; @@ -24,17 +24,21 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = '[LiveViewUtil]'; export class LiveViewUtil { - private context = application.getApplicationContext(); + private context: Context; private defaultLiveView?: liveViewManager.LiveView; private sequence: number = 0; + public constructor(context: Context) { + this.context = context; + } + public async startLiveView(params: RouteData) { // Verify that the live view switch is turned on if (!await LiveViewUtil.isLiveViewEnabled()) { hilog.error(0x0000, TAG, '%{public}s', 'Live view is disabled.'); return; } - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); this.updateLiveViewInfo(params); return await liveViewManager.startLiveView(this.defaultLiveView); @@ -65,7 +69,7 @@ export class LiveViewUtil { public async closeLiveView() { // Ensure that the sequence is greater than the current live window page. this.sequence++; - this.defaultLiveView = await this.createPrimaryLiveVie(); + this.defaultLiveView = await this.createPrimaryLiveView(); await liveViewManager.stopLiveView(this.defaultLiveView).then(() => { this.sequence = 0; this.defaultLiveView = undefined; @@ -76,6 +80,7 @@ export class LiveViewUtil { }); return; } + // [End closeLiveView] private static async isLiveViewEnabled(): Promise { @@ -118,7 +123,7 @@ export class LiveViewUtil { this.defaultLiveView = liveView; } - private async createPrimaryLiveVie(): Promise { + private async createPrimaryLiveView(): Promise { // [EndExclude createLiveView] // Construct live window request body. let liveView: liveViewManager.LiveView = { diff --git a/entry/src/main/ets/view/TrafficInfoView.ets b/entry/src/main/ets/view/TrafficInfoView.ets index c688693..0643923 100644 --- a/entry/src/main/ets/view/TrafficInfoView.ets +++ b/entry/src/main/ets/view/TrafficInfoView.ets @@ -78,7 +78,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).createLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).createLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, @@ -94,7 +94,7 @@ export struct TrafficInfoView { .width('40%') .onClick(() => { this.isShowButton = false; - LiveView.getInstance(this.getUIContext().getHostContext()).finishLiveView(); + LiveView.getInstance(this.getUIContext().getHostContext() as Context).finishLiveView(); this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast'), duration: 2000, -- Gitee From 83da038143ac877ef5ac15c9beec2032c6137d35 Mon Sep 17 00:00:00 2001 From: 26thE <962961353@qq.com> Date: Wed, 9 Jul 2025 10:46:26 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/utils/LiveViewUtil.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index eb060cf..75fd2c8 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -159,7 +159,7 @@ export class LiveViewUtil { private static async buildWantAgent(): Promise { const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ - bundleName: 'com.example.mapliveviewsample', + bundleName: '', abilityName: 'EntryAbility' } as Want], actionType: wantAgent.OperationType.START_ABILITIES, -- Gitee From 729eeca37779ce1367fd4889e3ef4eefb5409daa Mon Sep 17 00:00:00 2001 From: Fe26 Date: Thu, 10 Jul 2025 07:23:33 +0000 Subject: [PATCH 3/4] update entry/src/main/ets/utils/LiveViewUtil.ets. Signed-off-by: Fe26 --- entry/src/main/ets/utils/LiveViewUtil.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/utils/LiveViewUtil.ets b/entry/src/main/ets/utils/LiveViewUtil.ets index 75fd2c8..eb060cf 100644 --- a/entry/src/main/ets/utils/LiveViewUtil.ets +++ b/entry/src/main/ets/utils/LiveViewUtil.ets @@ -159,7 +159,7 @@ export class LiveViewUtil { private static async buildWantAgent(): Promise { const wantAgentInfo: wantAgent.WantAgentInfo = { wants: [{ - bundleName: '', + bundleName: 'com.example.mapliveviewsample', abilityName: 'EntryAbility' } as Want], actionType: wantAgent.OperationType.START_ABILITIES, -- Gitee From 8e12efa6e7ce9971b2d05a63d3989fad19990e41 Mon Sep 17 00:00:00 2001 From: Fe26 Date: Thu, 10 Jul 2025 07:39:36 +0000 Subject: [PATCH 4/4] update entry/src/main/ets/pages/Index.ets. Signed-off-by: Fe26 --- entry/src/main/ets/pages/Index.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 78957cc..b4a95d2 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -77,7 +77,7 @@ struct TipDialog { } @Entry -export struct LiveViewLockScreenPage { +struct LiveViewLockScreenPage { private customDialogController: CustomDialogController = new CustomDialogController({ builder: TipDialog({ onConfirm: () => { -- Gitee