当前位置:网站首页>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%')
}
}
边栏推荐
- go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
- Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- TCP congestion control details | 2 background
- Library management system (Shandong Agricultural University Curriculum Design)
- [error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
- Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
- LeetCode 4. 寻找两个正序数组的中位数(hard)
- Serial port controls steering gear rotation
- Unity Json 编写
- 基于多元时间序列对高考预测分析案例
猜你喜欢
大厂面试总结大全
Which software is good for machine vision?
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...
Serial port controls steering gear rotation
Typescript array out of order output
John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
数字IC手撕代码--投票表决器
数学分析_笔记_第5章:一元微分学
[cloud native] briefly talk about the understanding of flume, a massive data collection component
随机推荐
LeetCode 6. Zigzag transformation (n-shaped transformation)
数学分析_笔记_第5章:一元微分学
Unity uses ugui to set a simple multi-level horizontal drop-down menu (no code required)
vscode设置删除行快捷键[通俗易懂]
AcWing 300. Task arrangement
618深度复盘:海尔智家的制胜方法论
MySQL port
Routing mode: hash and history mode
⌈ 2022 ⌋ how to use webp gracefully in projects
LeetCode 3. 无重复字符的最长子串
月报总结|Moonbeam6月份大事一览
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
linux下配置Mysql授权某个用户远程访问,不受ip限制
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction
VMware安装win10镜像
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
LeetCode 2. Add two numbers
mysql数据库mysqldump为啥没有创建数据库的语句