使用uniApp打开鸿蒙应用
·
1.新建一个uni-app项目
一定要勾选uni-app-x,不然运行在鸿蒙模拟器上会闪退

找到项目下面的uni_modules

右键新建

3:取名+选择 比如我取名wq-openAppProduct
一定要勾选UTS插件-uni-app兼容模式组件(原“组件插件")

生成的项目文件

在package.json里面添加以下
"uni-ext-api": {
"uni": {
"openAppProduct": {
"name": "openAppProduct",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
}
添加位置

然后在wq-openAppProduct文件夹下面的 utssdk中新建app-harmony目录
在这个目录新建index.uts文件

import { common, Want } from '@kit.AbilityKit';
interface WantInfo {
bundleName : string,
abilityName : string
}
export function openAppProduct(option:WantInfo) {
let context = getContext() as common.UIAbilityContext;
let want: Want = {
deviceId: '', // 空字符串表示本设备
bundleName: option.bundleName, // 目标应用包名
abilityName: option.abilityName, // 目标Ability名称
};
context.startAbility(want);
}
取需要使用的地方 引入 我们鸿蒙代码里面写的方法就可以了
<template>`
<view>
<button type="primary" @click="submit">
登录
</button>
<button type="primary" @click="goto">
去首页
</button>
</view>
</template>
<script setup>
//去鸿蒙里面
const goto=()=>{
openAppProduct({
bundleName: 'com.example.myapplicationlv',
abilityName: 'EntryAbility'
})
}
</script>
<style lang="scss">
</style>
更多推荐


所有评论(0)