当前位置:网站首页>OpenHarmony如何启动远程设备的FA
OpenHarmony如何启动远程设备的FA
2022-07-02 13:51:00 【InfoQ】
启动本地设备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:
{
//设备Id,本机默认为空
deviceId:"",
//app名称,在config.json的bundleName
bundleName:"com.jianguo.openharmony",
//页面名称,注意包名
abilityName:"com.example.entry.SecondAbility"
}
- deviceId:进行说明本机默认为空,
- bundleName:在config.json的bundleName
- abilityName:页面名称,注意包名

跨设备启动FA
"reqPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
}
]

//设备管理器
import deviceMAnager from'@ohos.distributedHardware.deviceManager'
import featureAbilty from '@ohos.ability.featureAbility'
//设备管理器
import deviceMAnager from '@ohos.distributedHardware.deviceManager'
//远端app信息
import bundle from '@ohos.bundle';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
//动态申请权限,弹窗的形式,可以通用,注意修改两个地方,一个是包名,一个是权限列表
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> = []
//遍历权限是否通过
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() {
//页面即将显示的时候处理,运行时发送弹窗的形式去处理
requestPermision();
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button("跳转远程SecondAbility", {
type: ButtonType.Capsule
}).backgroundColor(Color.Orange).onClick((event: ClickEvent) => {
deviceMAnager.createDeviceManager("com.jianguo.openharmony", (err, value) => {
if (!err) {
let devManager = value;
//同步方式获得可信任列表
let deviceList = devManager.getTrustedDeviceListSync();
featureAbilty.startAbility({
want:
{
//设备Id,本机默认为空,这里只有两台设备,所以用数组[0]表示
deviceId: deviceList[0].deviceId,
//app名称,在config.json的bundleName
bundleName: "com.jianguo.openharmony",
//页面名称,注意包名
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%')
}
}
边栏推荐
- 618深度複盤:海爾智家的制勝方法論
- 月报总结|Moonbeam6月份大事一览
- Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
- Student course selection system (curriculum design of Shandong Agricultural University)
- Global and Chinese markets for airport baggage claim conveyors 2022-2028: technology, participants, trends, market size and share Research Report
- 学生选课系统(山东农业大学课程设计)
- Download blender on Alibaba cloud image station
- Serial port controls steering gear rotation
- sql解决连续登录问题变形-节假日过滤
- Unity Json 编写
猜你喜欢
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
TCP拥塞控制详解 | 2. 背景
DigiCert SSL证书支持中文域名申请吗?
SQL solves the problem of continuous login deformation holiday filtering
Mysql database mysqldump why there is no statement to create a database
⌈ 2022 ⌋ how to use webp gracefully in projects
小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求
Seal Library - installation and introduction
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
随机推荐
Yyds dry inventory KVM new inventory to expand space for home
什么是泛型?- 泛型入门篇
隐私计算技术创新及产业实践研讨会:学习
Yyds dry inventory executor package (parameter processing function)
学生选课系统(山东农业大学课程设计)
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
Yyds dry inventory company stipulates that all interfaces use post requests. Why?
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
Unity使用UGUI设置一个简单多级水平方向下拉菜单(不需要代码)
忆当年高考|成为程序员的你,后悔了吗?
LeetCode 1. 两数之和
Thinking about absolute truth and relative truth
LeetCode 3. Longest substring without duplicate characters
串口控制舵机转动
SSM integration exception handler and project exception handling scheme
Privacy computing technology innovation and industry practice seminar: Learning
What if the win11 app store cannot load the page? Win11 store cannot load page
Penetration tool - intranet permission maintenance -cobalt strike
基于多元时间序列对高考预测分析案例
只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!