From 517e4e9e27b12f2dea499dca17d2030278fa3273 Mon Sep 17 00:00:00 2001 From: HuangXW Date: Wed, 10 Aug 2022 14:22:18 +0800 Subject: [PATCH] =?UTF-8?q?ServiceExtensionAbility=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=8C=87=E5=AF=BC=E9=94=99=E8=AF=AF=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HuangXW --- .../ability/stage-serviceextension.md | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/zh-cn/application-dev/ability/stage-serviceextension.md b/zh-cn/application-dev/ability/stage-serviceextension.md index daf703a4ed..8cbaab3c4d 100644 --- a/zh-cn/application-dev/ability/stage-serviceextension.md +++ b/zh-cn/application-dev/ability/stage-serviceextension.md @@ -42,31 +42,34 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。 2. 开发者在定义Service的目录下创建TS文件,自定义类继承ServiceExtensionAbility,重写基类回调函数,示例如下: ```js + import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility' import rpc from '@ohos.rpc' + class StubTest extends rpc.RemoteObject { - constructor(des) { + constructor(des) { super(des); - } - onRemoteRequest(code, data, reply, option) { - } + } + onRemoteRequest(code, data, reply, option) { + } } - class ServiceExt extends ServiceExtensionAbility { - console.log('onCreate, want:' + want.abilityName); - } - onRequest(want, startId) { - console.log('onRequest, want:' + want.abilityName); - } - onConnect(want) { - console.log('onConnect , want:' + want.abilityName); - return new StubTest("test"); - } - onDisconnect(want) { - console.log('onDisconnect, want:' + want.abilityName); - } - onDestroy() { - console.log('onDestroy'); - } + class ServiceExtAbility extends ServiceExtensionAbility { + onCreate(want) { + console.log('onCreate, want:' + want.abilityName); + } + onRequest(want, startId) { + console.log('onRequest, want:' + want.abilityName); + } + onConnect(want) { + console.log('onConnect , want:' + want.abilityName); + return new StubTest("test"); + } + onDisconnect(want) { + console.log('onDisconnect, want:' + want.abilityName); + } + onDestroy() { + console.log('onDestroy'); + } } ``` ## 相关实例 -- GitLab