当前位置:网站首页>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
边栏推荐
- 智能垃圾桶(五)——点亮OLED
- 【Leetcode】14. Longest Common Prefix
- 将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus
- Microservice architecture practice: using Jenkins to realize automatic construction
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- 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
- Visibilitychange – refresh the page data when the specified tab is visible
- Sword finger offer 22 The penultimate node in the linked list
- A case study of college entrance examination prediction based on multivariate time series
- SAP Commerce Cloud Storefront 框架选型:Accelerator 还是 Spartacus?
猜你喜欢
A few lines of code to complete RPC service registration and discovery
Blog theme "text" summer fresh Special Edition
深度之眼(三)——矩阵的行列式
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
Exploration of mobile application performance tools
Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
默认浏览器设置不了怎么办?
【Leetcode】14. Longest Common Prefix
What if the default browser cannot be set?
剑指 Offer 25. 合并两个排序的链表
随机推荐
TCP拥塞控制详解 | 2. 背景
求简单微分方程
871. Minimum refueling times
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
executescalar mysql_ExecuteScalar()
Sword finger offer 26 Substructure of tree
Qstype implementation of self drawing interface project practice (II)
简单线性规划问题
Un an à dix ans
常用SQL语句(完整范例)
QStyle实现自绘界面项目实战(二)
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
一年顶十年
PCL知识点——体素化网格方法对点云进行下采样
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
ThreadLocal
13、Darknet YOLO3
详细介绍scrollIntoView()方法属性
一年頂十年
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers