当前位置:网站首页>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%')
}
}
边栏推荐
- Take you ten days to easily complete the go micro service series (I)
- LeetCode 1. Sum of two numbers
- Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
- 流批一体在京东的探索与实践
- PWM控制舵机
- LeetCode 5. 最长回文子串
- Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
- 图书管理系统(山东农业大学课程设计)
- 深度学习图像数据自动标注[通俗易懂]
猜你喜欢

LeetCode 1. 两数之和
![[cloud native] briefly talk about the understanding of flume, a massive data collection component](/img/2d/8c4769e97fb84e98eafb7069551341.png)
[cloud native] briefly talk about the understanding of flume, a massive data collection component

数学分析_笔记_第5章:一元微分学

基于多元时间序列对高考预测分析案例

小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求

July 1st gift: Yi Jingjie's "hundred day battle" ended perfectly, and the database of Guiyang bank was sealed in advance

路由模式:hash和history模式

七一献礼:易鲸捷 “百日会战”完美收官 贵阳银行数据库提前封板

Penetration tool - intranet permission maintenance -cobalt strike

Bib | graph representation based on heterogeneous information network learning to predict drug disease association
随机推荐
[fluent] dart data type list set type (define set | initialize | generic usage | add elements after initialization | set generation function | set traversal)
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
LeetCode 1. Sum of two numbers
Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification
pwm呼吸燈
Classic quotations
Data security industry series Salon (III) | data security industry standard system construction theme Salon
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
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
LeetCode 4. Find the median (hard) of two positive arrays
大厂面试总结大全
Yyds dry inventory company stipulates that all interfaces use post requests. Why?
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
Analysis of how to prevent virus in industrial computer
Understand the key technology of AGV -- the difference between laser slam and visual slam
Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
618深度复盘:海尔智家的制胜方法论
忆当年高考|成为程序员的你,后悔了吗?
Mysql database mysqldump why there is no statement to create a database
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus