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瀏覽量
17510 -
模型
+關注
關注
1文章
3261瀏覽量
48914 -
鴻蒙
+關注
關注
57文章
2369瀏覽量
42900
發布評論請先 登錄
相關推薦
鴻蒙開發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]提供了豐富的接口供外部
評論