Stage模型綁定FA模型ServiceAbility
本小節(jié)介紹Stage模型的兩種應(yīng)用組件如何綁定FA模型ServiceAbility組件。
開(kāi)發(fā)前請(qǐng)熟悉鴻蒙開(kāi)發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
UIAbility關(guān)聯(lián)訪問(wèn)ServiceAbility
UIAbility關(guān)聯(lián)訪問(wèn)ServiceAbility和UIAbility關(guān)聯(lián)訪問(wè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)訪問(wèn)ServiceAbility
下面以ServiceExtensionAbility為例來(lái)說(shuō)明ExtensionAbility關(guān)聯(lián)訪問(wèn)ServiceAbility。ServiceExtensionAbility關(guān)聯(lián)訪問(wèn)ServiceAbility和ServiceExtensionAbility關(guān)聯(lián)訪問(wè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文章
399瀏覽量
17434 -
模型
+關(guān)注
關(guān)注
1文章
3171瀏覽量
48711 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2309瀏覽量
42740
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論