提交 e2380554 编写于 作者: X xinking129

add stop interface to md file

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 4c1b4203
......@@ -13,6 +13,8 @@
- [通过跨设备Call调用实现多端协同](#通过跨设备call调用实现多端协同)
- [停止退出跨设备拉起的ServiceExtensionAbility组件](#停止退出跨设备拉起的ServiceExtensionAbility组件)
## 多端协同流程
......@@ -485,3 +487,85 @@
}
}
```
## 停止退出跨设备拉起的ServiceExtensionAbility组件
停止退出跨设备拉起的ServiceExtensionAbility组件。
下面介绍停止退出跨设备拉起的ServiceExtensionAbility组件的方法。
### 接口说明
**表5** Call API接口功能介绍
| 接口名 | 描述 |
| -------- | -------- |
| stopServiceExtensionAbility(want:&nbsp;Want):&nbsp;Promise&lt;void&gt;; | 停止退出启动的ServiceExtensionAbility,Promise形式接口。 |
| stopServiceExtensionAbility(want:&nbsp;Want,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void; | 停止退出启动的ServiceExtensionAbility,callback形式接口。 |
### 开发步骤
1. 停止退出跨设备远程启动的ServiceExtension应用。
使用stopServiceExtensionAbility接口停止退出由startAbility接口或connectServiceExtensionAbility接口拉起的跨设备ServiceExtension应用。
1. 导入接口模块
```ts
import Ability from '@ohos.app.ability.UIAbility';
```
or
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
```
2. 停止退出使用startAbility接口启动的跨设备ServiceExtension应用。
```ts
let deviceId = "device ID obtained from manager"
let want = {
deviceId: deviceId,
bundleName: "com.acts.actsstopserviceextensionmanualtest",
abilityName: "ServiceAbility",
};
this.context.startAbility(want).then(() => {
console.info("start ability success")
this.context.stopServiceExtensionAbility(want).then(() => {
console.info("stop service extension ability success")
}).catch((err) => {
console.info("stop service extension ability err is " + JSON.stringify(err))
})
}).catch((err) => {
console.info("start ability err is " + JSON.stringify(err))
})
```
3. 停止退出使用connectServiceExtensionAbility接口启动的跨设备ServiceExtension应用。
```ts
let deviceId = "device ID obtained from manager"
let want = {
deviceId: deviceId,
bundleName: "com.acts.actsstopserviceextensionmanualtest",
abilityName: "ServiceAbility",
};
let context = this.context;
let connectOptions = {
onConnect(elementName, remote) {
console.info("onConnect called elementName is {" + JSON.stringify(elementName) + "}" + " remote is {" + JSON.stringify(remote) + "}");
context.stopServiceExtensionAbility(want).then(() => {
console.info("stop service extension ability success")
}).catch((err) => {
console.info("stop service extension ability err is " + JSON.stringify(err))
})
},
onDisconnect(elementName) {
console.info("onDisconnect called elementName is {" + JSON.stringify(elementName) + "}");
},
onFailed(code) {
console.info("onFailed called elementName is {" + JSON.stringify(code) + "}");
}
}
this.context.connectServiceExtensionAbility(want, connectOptions)
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册