harmony 鸿蒙FA模型绑定Stage模型ServiceExtensionAbility

  • 2022-12-13
  • 浏览 (641)

FA模型绑定Stage模型ServiceExtensionAbility

本文介绍FA模型的三种应用组件如何绑定Stage模型的ServiceExtensionAbility组件。

PageAbility关联访问ServiceExtensionAbility

PageAbility关联访问ServiceExtensionAbility和PageAbility关联访问ServiceAbility的方式完全相同。

import featureAbility from '@ohos.ability.featureAbility';
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';

let want: Want = {
    bundleName: "com.ohos.stage",
    abilityName: "com.ohos.stage.ServiceExtensionAbility"
};

let faConnect: common.ConnectOptions = {
    onConnect: (elementName, proxy) => {
        console.info("Faconnection onConnect called.");
    },
    onDisconnect: (elementName) => {
        console.info("Faconnection onDisconnect called.");
    },
    onFailed: (code) => {
        console.info("Faconnection onFailed code is: " + code);
    }
};
let connectionId = featureAbility.connectAbility(want, faConnect);

ServiceAbility/DataAbility关联访问ServiceExtensionAbility

ServiceAbility/DataAbility关联访问ServiceExtensionAbility和ServiceAbility/DataAbility关联访问ServiceAbility的方式完全相同。

import particleAbility from '@ohos.ability.particleAbility';
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';

let want: Want = {
    bundleName: "com.ohos.stage",
    abilityName: "com.ohos.stage.ServiceExtensionAbility"
};

let faConnect: common.ConnectOptions = {
    onConnect: (elementName, proxy) => {
        console.info("Faconnection onConnect called.");
    },
    onDisconnect: (elementName) => {
        console.info("Faconnection onDisconnect called.");
    },
    onFailed: (code) => {
        console.info("Faconnection onFailed code is: " + code);
    }
};
let connectionId = particleAbility.connectAbility(want, faConnect);

你可能感兴趣的鸿蒙文章

harmony 鸿蒙应用模型

harmony 鸿蒙使用显式Want启动应用组件

harmony 鸿蒙使用隐式Want打开网址

harmony 鸿蒙AbilityStage组件容器

harmony 鸿蒙访问DataAbility

harmony 鸿蒙FA模型访问Stage模型DataShareExtensionAbility

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙常见action与entities

harmony 鸿蒙API切换概述

harmony 鸿蒙app和deviceConfig的切换

0  赞