当前位置:网站首页>How openharmony starts FA of remote devices
How openharmony starts FA of remote devices
2022-07-02 16:53:00 【InfoQ】
Start local device FA






@State message: string = 'SecondAbility'

{
"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
}
}
]
}
}
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"
}
- deviceId: For description, this machine defaults to empty ,
- bundleName: stay config.json Of bundleName
- abilityName: Page name , Pay attention to the package name

Cross device startup FA
"reqPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
}
]

// 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))
})
}
@Entry
@Component
struct 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%')
}
}
边栏推荐
- Student course selection system (curriculum design of Shandong Agricultural University)
- Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
- Digital IC hand tearing code -- voting device
- Aujourd'hui dans l'histoire: Alipay lance le paiement par code à barres; La naissance du père du système de partage du temps; La première publicité télévisée au monde...
- 【云原生】简单谈谈海量数据采集组件Flume的理解
- Thinking about absolute truth and relative truth
- Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
- 易语言abcd排序
- PCL 点云镜像变换
猜你喜欢

隐私计算技术创新及产业实践研讨会:学习

PWM breathing lamp

Which software is good for machine vision?

Privacy computing technology innovation and industry practice seminar: Learning

路由模式:hash和history模式

PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御

Kubernetes three open interfaces first sight

pwm呼吸燈

Typescript array out of order output

LeetCode 2. 两数相加
随机推荐
Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
Kubernetes three open interfaces first sight
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
VMware安装win10镜像
Unity Json 编写
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
Summary of monthly report | list of major events of moonbeam in June
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Executive engine module of high performance data warehouse practice based on Impala
【云原生】简单谈谈海量数据采集组件Flume的理解
大廠面試總結大全
Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
PCL 最小中值平方法拟合平面
LeetCode 2. 两数相加
unity Hub 登录框变得很窄 无法登录
数学分析_笔记_第5章:一元微分学
What is normal distribution? What is the 28 law?
Penetration tool - intranet permission maintenance -cobalt strike