From b7fca7ed64ed213a133fd45836aecdc2733d2173 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 14 Dec 2024 17:12:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0flutter=5Fpage=5Fsample2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- ohos/flutter_page_sample2/ohos/build-profile.json5 | 1 - .../src/main/ets/entryability/BatteryPlugin.ets | 14 ++++++++++++-- .../src/main/ets/entryability/MyFlutterEntry.ets | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ohos/flutter_page_sample2/ohos/build-profile.json5 b/ohos/flutter_page_sample2/ohos/build-profile.json5 index 3dce1199..0d8b167e 100644 --- a/ohos/flutter_page_sample2/ohos/build-profile.json5 +++ b/ohos/flutter_page_sample2/ohos/build-profile.json5 @@ -20,7 +20,6 @@ { "name": "default", "signingConfig": "default", - "compileSdkVersion": "5.0.0(12)", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", } diff --git a/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/BatteryPlugin.ets b/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/BatteryPlugin.ets index adb31605..71b0caa2 100644 --- a/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/BatteryPlugin.ets +++ b/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/BatteryPlugin.ets @@ -14,10 +14,11 @@ */ import { + AbilityAware, + AbilityPluginBinding, Any, BasicMessageChannel, EventChannel, - FlutterManager, FlutterPlugin, Log, MethodCall, @@ -32,14 +33,23 @@ import { Reply } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessag const TAG = "BatteryPluginTag"; -export default class BatteryPlugin implements FlutterPlugin { +export default class BatteryPlugin implements FlutterPlugin, AbilityAware { private channel?: MethodChannel; private basicChannel?: BasicMessageChannel; private eventChannel?: EventChannel; private eventSink?: EventSink; private api = new BatteryApi(); + onAttachedToAbility(binding: AbilityPluginBinding): void { + Log.i(TAG, "onAttachedToAbility") + } + + onDetachedFromAbility(): void { + Log.i(TAG, "onDetachedFromAbility") + } + onAttachedToEngine(binding: FlutterPluginBinding): void { + Log.i(TAG, "onAttachedToEngine"); this.channel = new MethodChannel(binding.getBinaryMessenger(), "samples.flutter.dev/battery"); let that = this; this.channel.setMethodCallHandler({ diff --git a/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/MyFlutterEntry.ets b/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/MyFlutterEntry.ets index 8b0d906f..796c95e3 100644 --- a/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/MyFlutterEntry.ets +++ b/ohos/flutter_page_sample2/ohos/entry/src/main/ets/entryability/MyFlutterEntry.ets @@ -20,6 +20,6 @@ export default class MyFlutterEntry extends FlutterEntry { configureFlutterEngine(flutterEngine: FlutterEngine): void { super.configureFlutterEngine(flutterEngine); GeneratedPluginRegistrant.registerWith(flutterEngine); - this.delegate?.addPlugin(new BatteryPlugin()); + this.addPlugin(new BatteryPlugin()); } } -- Gitee