FA模型綁定Stage模型ServiceExtensionAbility
本文介紹FA模型的三種應(yīng)用組件如何綁定Stage模型的ServiceExtensionAbility組件。
開(kāi)發(fā)前請(qǐng)熟悉鴻蒙開(kāi)發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
PageAbility關(guān)聯(lián)訪問(wèn)ServiceExtensionAbility
PageAbility關(guān)聯(lián)訪問(wèn)ServiceExtensionAbility和PageAbility關(guān)聯(lián)訪問(wèn)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關(guān)聯(lián)訪問(wèn)ServiceExtensionAbility
ServiceAbility/DataAbility關(guān)聯(lián)訪問(wèn)ServiceExtensionAbility和ServiceAbility/DataAbility關(guān)聯(lián)訪問(wèn)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 {
// 啟動(dòng)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));
});
// 訪問(wèn)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();
審核編輯 黃宇
-
框架
+關(guān)注
關(guān)注
0文章
403瀏覽量
17475 -
模型
+關(guān)注
關(guān)注
1文章
3226瀏覽量
48807 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2339瀏覽量
42805
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論