当前位置:网站首页>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%')
}
}
边栏推荐
- ROW_NUMBER()、RANK()、DENSE_RANK区别
- uboot的作用和功能
- 基于Impala的高性能数仓实践之执行引擎模块
- July 1st gift: Yi Jingjie's "hundred day battle" ended perfectly, and the database of Guiyang bank was sealed in advance
- Yyds dry inventory company stipulates that all interfaces use post requests. Why?
- 隐私计算技术创新及产业实践研讨会:学习
- 基于多元时间序列对高考预测分析案例
- LeetCode 5. Longest Palindromic Substring
- 大厂面试总结大全
- 只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!
猜你喜欢

Understand the key technology of AGV -- the difference between laser slam and visual slam

分析超700万个研发需求发现,这8门编程语言才是行业最需要的!

Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus

Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm

月报总结|Moonbeam6月份大事一览

电脑管理员权限在哪里可以打开

Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation

PWM breathing lamp

unity Hub 登录框变得很窄 无法登录

Bib | graph representation based on heterogeneous information network learning to predict drug disease association
随机推荐
What if the win11 app store cannot load the page? Win11 store cannot load page
Library management system (Shandong Agricultural University Curriculum Design)
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
Digital IC hand tearing code -- voting device
Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
国内比较好的OJ平台[通俗易懂]
LeetCode 6. Zigzag transformation (n-shaped transformation)
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Written by unity Jason
What is normal distribution? What is the 28 law?
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
数据安全产业系列沙龙(三)| 数据安全产业标准体系建设主题沙龙
According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
LeetCode 5. 最长回文子串
Typescript array out of order output
渗透工具-内网权限维持-Cobalt strike
电脑设备打印机驱动安装失败如何解决