FA模型绑定Stage模型ServiceExtensionAbility
本文介绍FA模型的三种应用组件如何绑定Stage模型的ServiceExtensionAbility组件。
开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
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';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
const TAG: string = 'PageInterflowFaAndStage';
const domain: number = 0xFF00;
@Entry
@Component
struct PageInterflowFaAndStage {
build() {
Column() {
// ...
List({ initialIndex: 0 }) {
ListItem() {
Row() {
// ...
}
.onClick(() = > {
let want: Want = {
bundleName: 'ohos.samples.etsclock',
abilityName: 'MainAbility'
};
featureAbility.startAbility({ want }).then((code) = > {
hilog.info(domain, TAG, 'Ability verify code: ' + JSON.stringify(code));
}).catch((error: BusinessError) = > {
hilog.error(domain, TAG, 'Ability failed: ' + JSON.stringify(error));
});
let serviceWant: Want = {
bundleName: 'com.samples.stagemodelabilityinteraction',
abilityName: 'ServiceExtAbility'
};
let faConnect: common.ConnectOptions = {
onConnect: (elementName, proxy) = > {
hilog.info(domain, TAG, "FaConnection onConnect called.");
},
onDisconnect: (elementName) = > {
hilog.info(domain, TAG, "FaConnection onDisconnect called.");
},
onFailed: (code) = > {
hilog.info(domain, TAG, "FaConnection onFailed code is: " + code);
}
};
let connectionId = featureAbility.connectAbility(serviceWant, faConnect);
})
}
// ...
}
// ...
}
// ...
}
}
ServiceAbility/DataAbility关联访问ServiceExtensionAbility
ServiceAbility/DataAbility关联访问ServiceExtensionAbility和ServiceAbility/DataAbility关联访问ServiceAbility的方式完全相同。HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿
import type common from '@ohos.app.ability.common';
import particleAbility from '@ohos.ability.particleAbility';
import type Want from '@ohos.app.ability.Want';
import type { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
const TAG: string = '[Sample_FAModelAbilityDevelop]';
const domain: number = 0xFF00;
class ServiceAbilityStartUiAbility {
onStart(): void {
// 启动UIAbility
let want: Want = {
bundleName: 'ohos.samples.etsclock',
abilityName: 'MainAbility'
};
particleAbility.startAbility({ want }).then(() = > {
hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Start Ability successfully.');
}).catch((error: BusinessError) = > {
hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Ability failed: ' + JSON.stringify(error));
});
// 访问ServiceExtensionAbility
let serviceWant: Want = {
bundleName: 'com.samples.stagemodelabilityinteraction',
abilityName: 'ServiceExtAbility'
};
let faConnect: common.ConnectOptions = {
onConnect: (elementName, proxy) = > {
hilog.info(domain, TAG, 'FaConnection onConnect called.');
},
onDisconnect: (elementName) = > {
hilog.info(domain, TAG, 'FaConnection onDisconnect called.');
},
onFailed: (code) = > {
hilog.info(domain, TAG, 'FaConnection onFailed code is: ' + code);
}
};
let connectionId = particleAbility.connectAbility(serviceWant, faConnect);
hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility ServiceAbility onStart');
}
};
export default new ServiceAbilityStartUiAbility();
审核编辑 黄宇
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
框架
+关注
关注
0文章
403浏览量
17477 -
模型
+关注
关注
1文章
3229浏览量
48813 -
鸿蒙
+关注
关注
57文章
2345浏览量
42822
发布评论请先 登录
相关推荐
鸿蒙开发Ability Kit程序框架服务:FA模型切换Stage模型指导 module的切换
从FA模型切换到Stage模型时,开发者需要将config.json文件module标签下的配置迁移到module.json5配置文件mod
鸿蒙开发Ability Kit程序框架服务:FA模型切换Stage模型指导 app和deviceConfig的切换
为了便于开发者维护应用级别的属性配置,Stage模型将config.json中的app和deviceConfig标签提取到了app.json5中进行配置,并对部分标签名称进行了修改,具体差异见下表。
鸿蒙Ability Kit(程序框架服务)【组件启动规则(Stage模型)】
组件启动规则(Stage模型) 启动组件是指一切启动或连接应用组件的行为: 启动UIAbility、ServiceExtensionAbility、DataShareExtensionAbility
鸿蒙Ability Kit(程序框架服务)【Ability与ServiceExtensionAbility通信】
本示例展示通过[IDL的方式]和 [@ohos.rpc] 等接口实现了Ability与ServiceExtensionAbility之间的通信。
鸿蒙Ability Kit(程序框架服务)【ServiceExtensionAbility】
[ServiceExtensionAbility]是SERVICE类型的ExtensionAbility组件,提供后台服务能力,其内部持有了一个[ServiceExtensionContext],通过[ServiceExtensionContext]提供了丰富的接口供外部
评论