当前位置:网站首页>How openharmony starts fa (local and remote)
How openharmony starts fa (local and remote)
2022-07-02 17:29:00 【Hua Weiyun】
Hello everyone , Today, let's learn about distributed related content , In fact, for distributed task scheduling , Is another form of data management
Start local device FA
First create a project
As shown in the figure :

Click on finish that will do
Then let's start with some basic settings
We will be having DAYU200 Run this instance on the development board , So make a signature setting
Click on File--- Project Struct,

And then click Signing Configs Complete signature settings

Click on ok Will complete automatic signature . In the here , Our first step is finished , Next, let's take a look at the next step
Back to our theme today , We are going to start another local FA, But there is only one , So we need to create another one at this time
stay entry Modules click New-Ability-PageAbility, You can create another FA, We call it SecondAbility


As shown in the figure below , We've created it

modify SecondAbility Default in message
@State message: string = 'SecondAbility'Here, our second step is finished
Because we started it locally FA, In order to distinguish the remote startup FA, So we need to rename the file , This is convenient for us to know .
We click MainAbility‘ Medium index.ets, Right click to rename

Complete the above steps , The editor will help us with onfig.json Refactoring the project
{ "app": { "vendor": "example", "bundleName": "com.jianguo.openharmony", "version": { "code": 1000000, "name": "1.0.0" } }, "deviceConfig": {}, "module": { "mainAbility": ".MainAbility", "deviceType": [ "phone", "tablet" ], "abilities": [ { "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ] } ], "orientation": "unspecified", "visible": true, "srcPath": "MainAbility", "name": ".MainAbility", "srcLanguage": "ets", "icon": "$media:icon", "description": "$string:MainAbility_desc", "formsEnabled": false, "label": "$string:MainAbility_label", "type": "page", "launchType": "standard" }, { "orientation": "unspecified", "srcPath": "SecondAbility", "name": ".SecondAbility", "srcLanguage": "ets", "icon": "$media:icon", "description": "$string:SecondAbility_desc", "formsEnabled": false, "label": "$string:SecondAbility_label", "type": "page", "launchType": "standard" } ], "distro": { "moduleType": "entry", "installationFree": false, "deliveryWithInstall": true, "moduleName": "entry" }, "package": "com.example.entry", "srcPath": "", "name": ".entry", "js": [ { "mode": { "syntax": "ets", "type": "pageAbility" }, "pages": [ "pages/start_local_fa" ], "name": ".MainAbility", "window": { "designWidth": 720, "autoDesignWidth": false } }, { "mode": { "syntax": "ets", "type": "pageAbility" }, "pages": [ "pages/index" ], "name": ".SecondAbility", "window": { "designWidth": 720, "autoDesignWidth": false } } ] }}Next, let's take a look at the most critical step , How to start local FA
We can use a button Button to jump it
The main thing is onclick The events inside
As shown in the figure below :
Pay attention to importing packages when using :
import featureAbiltty from '@ohos.ability.featureAbility'featureAbiltty.startAbility({ want: { // equipment Id, This machine defaults to empty deviceId:"", //app name , stay config.json Of bundleName bundleName:"com.jianguo.openharmony", // Page name , Pay attention to the package name abilityName:"com.example.entry.SecondAbility" }Then I'm on the top
deviceId: For description, this machine defaults to empty ,
bundleName: stay config.json Of bundleName
abilityName: Page name , Pay attention to the package name

And then we were in DATU20 function
Find that you can jump , Then we have achieved this function
Cross device startup FAs
Next, let's see how to start the remote deviceId
before this , All we need to do is , stay config.json Configure permissions
Just define non sensitive permissions here , If it is a sensitive permission , It is necessary to send a pop-up window to deal with it at runtime .
"reqPermissions": [ { "name": "ohos.permission.DISTRIBUTED_DATASYNC" } ]
Precautions for remote startup :
jurisdiction deviceId
Dynamic application authority
// Device manager import deviceMAnager from'@ohos.distributedHardware.deviceManager'import featureAbilty from '@ohos.ability.featureAbility'// Device manager import deviceMAnager from '@ohos.distributedHardware.deviceManager'// Distal app Information import bundle from '@ohos.bundle';import abilityAccessCtrl from '@ohos.abilityAccessCtrl';// Dynamic application authority , Pop up window form , Can be used in general , Pay attention to modifying two places , One is the package name , One is the permission list async function requestPermision() { let array: Array<string> = ["ohos.permission.DISTRIBUTED_DATASYNC"] const appInfo = await bundle.getApplicationInfo("com.jianguo.openharmony", 0, 100) let tolenId = appInfo.accessTokenId; const atManger = abilityAccessCtrl.createAtManager(); let requestPressions: Array<string> = [] // Traverse whether the permission passes for (let i = 0;i < array.length; i++) { let result = await atManger.verifyAccessToken(tolenId, array[i]); if (result != abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { requestPressions.push(array[i]); } } if (requestPressions.length == 0 || requestPressions == []) { return; } let context = featureAbilty.getContext(); context.requestPermissionsFromUser(requestPressions, 1, (data) => { console.info("XXXXXX data" + JSON.stringify(data)) })}@[email protected] Index { @State message: string = 'MainAbility' aboutToAppear() { // When the page is about to be displayed , The runtime sends a pop-up window to handle requestPermision(); } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) Button(" Jump to remote SecondAbility", { type: ButtonType.Capsule }).backgroundColor(Color.Orange).onClick((event: ClickEvent) => { deviceMAnager.createDeviceManager("com.jianguo.openharmony", (err, value) => { if (!err) { let devManager = value; // Get the trusted list by synchronization let deviceList = devManager.getTrustedDeviceListSync(); featureAbilty.startAbility({ want: { // equipment Id, This machine defaults to empty , There are only two devices here , So use arrays [0] Express deviceId: deviceList[0].deviceId, //app name , stay config.json Of bundleName bundleName: "com.jianguo.openharmony", // Page name , Pay attention to the package name abilityName: "com.example.entry.SecondAbility" } }).then((value) => { console.log("Succes Data" + JSON.stringify(value)) }).catch((error) => { console.log("failed Data" + JSON.stringify(error)) }) } }) }).width(199) } .width('100%') } .height('100%') }}Connect local service
Why connect locally service, Background interaction needs
First create a local service
stay entry Modules click New-Ability-ServiceAbility, You can create another FA, We call it ServiceAbility, Click on Finish

You can see this information in the default file , Actually, we don't need , We can remove
export default { onStart() { console.info('ServiceAbility onStart'); }, onStop() { console.info('ServiceAbility onStop'); }, onCommand(want, startId) { console.info('ServiceAbility onCommand'); }};Basic components
边栏推荐
- Si446 usage record (II): generate header files using wds3
- 体验居家办公完成项目有感 | 社区征文
- After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
- TCP congestion control details | 2 background
- ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
- 剑指 Offer 22. 链表中倒数第k个节点
- 什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
- 智能垃圾桶(五)——点亮OLED
- What if the default browser cannot be set?
- 博客主题 “Text“ 夏日清新特别版
猜你喜欢

13、Darknet YOLO3

Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei

QWebEngineView崩溃及替代方案

Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan

Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)

Eye of depth (II) -- matrix and its basic operations

剑指 Offer 24. 反转链表

福元医药上交所上市:市值105亿 胡柏藩身价超40亿

TCP congestion control details | 2 background

ETH数据集下载及相关问题
随机推荐
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
Explanation of traceroute command
博客主题 “Text“ 夏日清新特别版
超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
书包网小说多线程爬虫[通俗易懂]
ROS知识点——消息过滤器 ( message_filters)
剑指 Offer 25. 合并两个排序的链表
easyswoole3.2重启不成功
Ocio V2 reverse LUT
如何给 SAP Spartacus Storefront 创建新的页面
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权
线性规划例题 投资的收益与风险
Qstype implementation of self drawing interface project practice (II)
Dstat use [easy to understand]
Vscode knowledge points - Common Errors
Shutter: action feedback
A case study of college entrance examination prediction based on multivariate time series
牛客 JS3 分隔符