当前位置:网站首页>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
边栏推荐
- ThreadLocal
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- 链表求和[dummy+尾插法+函数处理链表引用常见坑位]
- Helm kubernetes package management tool
- Experience home office, feel the completion of the project | community essay solicitation
- Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
- 綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
- 将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus
- si446使用记录(二):使用WDS3生成头文件
- Eye of depth (II) -- matrix and its basic operations
猜你喜欢

剑指 Offer 24. 反转链表

Exploration of mobile application performance tools

Income and risk of linear programming example investment

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

Qstype implementation of self drawing interface project practice (II)

Si446 usage record (II): generate header files using wds3

13、Darknet YOLO3

TCP拥塞控制详解 | 2. 背景

Smart trash can (V) - light up OLED

From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
随机推荐
剑指 Offer 24. 反转链表
How to transfer business data with BorgWarner through EDI?
[shutter] dart data type (dynamic data type)
Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
Sword finger offer 26 Substructure of tree
Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
The difference between class and getClass ()
Use of openpose
博客主题 “Text“ 夏日清新特别版
Use the API port of the bridge of knowledge and action to provide resources for partners to access
深度之眼(三)——矩阵的行列式
Vscode + eslint configuration
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
选择 SAP Spartacus 作为 SAP Commerce Cloud Storefront 实现框架的五个理由
Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
【Leetcode】14. Longest Common Prefix
TCP congestion control details | 2 background
si446使用记录(二):使用WDS3生成头文件
The difference of message mechanism between MFC and QT