Stage模型綁定FA模型ServiceAbility
本小節(jié)介紹Stage模型的兩種應(yīng)用組件如何綁定FA模型ServiceAbility組件。
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
UIAbility關(guān)聯(lián)訪問ServiceAbility
UIAbility關(guān)聯(lián)訪問ServiceAbility和UIAbility關(guān)聯(lián)訪問ServiceExtensionAbility的方式完全相同。
import { common, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { promptAction } from '@kit.ArkUI';
const TAG: string = '[Page_StartFAModel]';
const DOMAIN_NUMBER: number = 0xFF00;
@Entry
@Component
struct Page_StartFAModel {
private context = getContext(this) as common.UIAbilityContext;
build() {
Column() {
// ...
List({ initialIndex: 0 }) {
// ...
ListItem() {
Row() {
// ...
}
.onClick(() = > {
let want: Want = {
bundleName: 'com.samples.famodelabilitydevelop',
abilityName: 'com.samples.famodelabilitydevelop.ServiceAbility',
};
let options: common.ConnectOptions = {
onConnect: (elementName, proxy) = > {
hilog.info(DOMAIN_NUMBER, TAG, 'onConnect called.');
promptAction.showToast({
message: $r('app.string.ConnectFAServiceAbility')
});
},
onDisconnect: (elementName) = > {
hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect called.');
},
onFailed: (code) = > {
hilog.info(DOMAIN_NUMBER, TAG, 'onFailed code is: ' + code);
}
};
let connectionId = this.context.connectServiceExtensionAbility(want, options);
hilog.info(DOMAIN_NUMBER, TAG, 'connectionId is ' + JSON.stringify(connectionId));
})
}
// ...
}
// ...
}
// ...
}
}
ExtensionAbility關(guān)聯(lián)訪問ServiceAbility
下面以ServiceExtensionAbility為例來說明ExtensionAbility關(guān)聯(lián)訪問ServiceAbility。ServiceExtensionAbility關(guān)聯(lián)訪問ServiceAbility和ServiceExtensionAbility關(guān)聯(lián)訪問ServiceExtensionAbility的方式完全相同。
HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
import { common, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { promptAction } from '@kit.ArkUI';
const TAG: string = '[Page_StartFAModel]';
const DOMAIN_NUMBER: number = 0xFF00;
@Entry
@Component
struct Page_StartFAModel {
private context = getContext(this) as common.UIAbilityContext;
build() {
Column() {
// ...
List({ initialIndex: 0 }) {
// ...
ListItem() {
Row() {
// ...
}
.onClick(() = > {
let want: Want = {
bundleName: 'com.samples.famodelabilitydevelop',
abilityName: 'com.samples.famodelabilitydevelop.ServiceAbility',
};
let options: common.ConnectOptions = {
onConnect: (elementName, proxy) = > {
hilog.info(DOMAIN_NUMBER, TAG, 'onConnect called.');
promptAction.showToast({
message: $r('app.string.ConnectFAServiceAbility')
});
},
onDisconnect: (elementName) = > {
hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect called.');
},
onFailed: (code) = > {
hilog.info(DOMAIN_NUMBER, TAG, 'onFailed code is: ' + code);
}
};
let connectionId = this.context.connectServiceExtensionAbility(want, options);
hilog.info(DOMAIN_NUMBER, TAG, 'connectionId is ' + JSON.stringify(connectionId));
})
}
// ...
}
// ...
}
// ...
}
}
審核編輯 黃宇
-
框架
+關(guān)注
關(guān)注
0文章
403瀏覽量
17489 -
模型
+關(guān)注
關(guān)注
1文章
3243瀏覽量
48842 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2352瀏覽量
42859
發(fā)布評論請先 登錄
相關(guān)推薦
評論