当前位置:网站首页>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
边栏推荐
- Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
- uniapp H5页面调用微信支付
- Eye of depth (III) -- determinant of matrix
- Microservice architecture practice: using Jenkins to realize automatic construction
- 线性规划例题 投资的收益与风险
- 871. Minimum refueling times
- Helm kubernetes package management tool
- 智能垃圾桶(五)——点亮OLED
- Eye of depth (II) -- matrix and its basic operations
- [web technology] 1233 seconds understand web component
猜你喜欢

社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东

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

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

剑指 Offer 26. 树的子结构

关于我

剑指 Offer 22. 链表中倒数第k个节点

QStyle实现自绘界面项目实战(二)

剑指 Offer 25. 合并两个排序的链表

畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权

Qwebengineview crash and alternatives
随机推荐
Sword finger offer 24 Reverse linked list
Exploration of mobile application performance tools
Ocio V2 reverse LUT
[shutter] dart data type (dynamic data type)
TCP congestion control details | 2 background
【Leetcode】14. Longest Common Prefix
The construction of scalable distributed database cluster and the partition design of oneproxy sub database
easyswoole3.2重启不成功
executescalar mysql_ ExecuteScalar()
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
什么是敏捷开发流程
Visibilitychange – refresh the page data when the specified tab is visible
求简单微分方程
How to transfer business data with BorgWarner through EDI?
微信小程序 —— 上下浮动的箭头
ROS knowledge point - message_filters
ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
Qstype implementation of self drawing interface project practice (II)