更新记录
1.0.0(2025-07-05)
初始化
平台兼容性
uni-app(4.05)
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | - | - | - | - | 5.0 | × | √ |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
- | - | - | - | - | - | - | - | - | - | - |
uni-app x(4.05)
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | 5.0 | × | √ | - |
其他
多语言 | 暗黑模式 | 宽屏模式 |
---|---|---|
× | × | √ |
axl-float-camera
插件测试使用方法
-
选择试用,绑定要试用的项目appid,
-
选择后下载到对应的本地项目,
-
按照文档 -》把插件引入项目(即 import { startBackgroundService, stopBackgroundService, setCameraId, setInitialPosition, setCloseCallback, setCameraFacing, setWindowSize, setShowCloseButton, setDisplayOrientation } from "@/uni_modules/axl-float-camera" 需要先引入),
-
发布-》云打包-》选择制作基座-》打包等基座制作完成
-
运行 -》 运行到手机或模拟器-》运行到Androidapp基座-》选择使用自定义基座运行-》选择手机-》运行
-
之前若安装过基座 ,请卸载之前的基座
测试请注意 所有的设置都要在打开悬浮窗之前进行设置
代码使用示例
<template>
<view class="content">
<button type="primary" class="btn" @click="checkFloatPermission">检测悬浮窗权限</button>
<button type="primary" class="btn" @click="checkCameraPermission">检测相机权限</button>
<button type="primary" class="btn" @click="setFloat">设置悬浮窗大小</button>
<button type="primary" class="btn" @click="setposi">设置悬浮窗位置</button>
<button type="primary" class="btn" @click="closeBtn">是否显示悬浮窗按钮</button>
<button type="primary" class="btn" @click="setCamerNum">设置摄像头</button>
<button type="primary" class="btn" @click="setCameraFaci">设置相机前置后置</button>
<button type="primary" class="btn" @click="setDisplay">设置相机角度</button>
<button type="primary" class="btn" @click="openFloat">打开悬浮窗</button>
<button type="primary" class="btn" @click="closeFloat">关闭悬浮窗</button>
</view>
</template>
<script>
import {
startBackgroundService,
stopBackgroundService,
setCameraId,
setInitialPosition,
setCloseCallback,
setCameraFacing,
setWindowSize,
setShowCloseButton,
setDisplayOrientation
} from "@/uni_modules/axl-float-camera"
export default {
data() {
return {
}
},
onLoad() {
},
mounted() {
},
methods: {
//检测是否有相机权限,没有则自动设置
async checkCameraPermission() {
try {
// 1. 检查权限状态
const main = plus.android.runtimeMainActivity();
const PackageManager = plus.android.importClass('android.content.pm.PackageManager');
// 更可靠的权限检查方法
const checkPermission = () => {
return main.checkSelfPermission('android.permission.CAMERA') === PackageManager
.PERMISSION_GRANTED;
};
// 2. 解析权限结果
console.log(checkPermission())
if (checkPermission()) {
uni.showToast({
title: "已有权限",
icon: "none"
})
return true;
} else {
// 3. 无权限时请求授权
const authResult = await new Promise((resolve) => {
plus.android.requestPermissions(
['android.permission.CAMERA'],
resolve,
resolve
);
});
// 4. 处理授权结果
const isGranted = checkPermission();
console.log(isGranted)
if (!isGranted) {
uni.showModal({
title: '权限提示',
content: '需要相机权限才能使用摄像头功能',
confirmText: '去设置',
success: (res) => {
if (res.confirm) {
// 打开应用设置页面
const main = plus.android.runtimeMainActivity();
const Intent = plus.android.importClass('android.content.Intent');
const Settings = plus.android.importClass(
'android.provider.Settings');
const Uri = plus.android.importClass('android.net.Uri');
const intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
const packageName = main.getPackageName();
const uri = Uri.fromParts("package", packageName, null);
intent.setData(uri);
// 添加FLAG_ACTIVITY_NEW_TASK标志
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// 启动Activity
main.startActivity(intent);
}
}
});
}
return isGranted;
}
} catch (e) {
console.error('权限检查错误:', e);
return false;
}
},
//检测是否有悬浮窗权限,没有则跳转设置
async checkFloatPermission() {
let main = plus.android.runtimeMainActivity();
let Intent = plus.android.importClass("android.content.Intent");
let Settings = plus.android.importClass("android.provider.Settings");
let Uri = plus.android.importClass("android.net.Uri");
const hasPermission = Settings.canDrawOverlays(main);
if (hasPermission) {
uni.showToast({
title: "已有权限",
icon: "none"
})
} else {
let intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
intent.setData(Uri.parse("package:" + main.getPackageName()));
main.startActivityForResult(intent, 0);
}
},
openFloat() {
// 设置关闭回调
setCloseCallback((message) => {
console.log("收到关闭回调:", message);
})
//打开悬浮窗
startBackgroundService();
},
closeFloat() {
//关闭悬浮窗
stopBackgroundService();
},
setFloat() {
//设置窗体的宽高
setWindowSize(600, 400);
},
closeBtn() {
//是否显示悬浮窗口内的关闭按钮
setShowCloseButton(false)
},
setCameraFaci() {
//设置摄像头 前置(front)、后置(back)
setCameraFacing('front')
},
setCamerNum() {
//如果有多个摄像头可以指定摄像头id,不设置则使用默认
setCameraId(0);
},
setposi() {
//设置悬浮窗显示的位置,可以设置值top-left、top-right(默认)、bottom-left、bottom-right、custom(自定义,根据自己的设备调试位置)
setInitialPosition('custom', 100, 250);
},
setDisplay() {
//默认0
setDisplayOrientation(90);
},
}
}
</script>
api 介绍
打开悬浮窗
startBackgroundService
startBackgroundService()
关闭悬浮窗
stopBackgroundService
stopBackgroundService()
设置关闭回调
setCloseCallback
setCloseCallback((message) => {
console.log("收到关闭回调:", message);
})
设置窗体的宽和高
setWindowSize
setWindowSize(600, 400)
设置悬浮窗显示的位置
setInitialPosition
可以设置值top-left、top-right(默认)、bottom-left、bottom-right、custom(自定义,根据自己的设备调试位置)
setInitialPosition('custom', 100, 250)
是否显示悬浮窗口内的关闭按钮
setShowCloseButton
是否显示悬浮窗右上角的关闭按钮 true 显示,false不显示
setShowCloseButton(false)
设置摄像头
setCameraId
如果有多个摄像头可以指定摄像头id,不设置则使用默认第一个
setCameraId(0);
设置摄像头 前置(front)、后置(back)
setCameraFacing
setCameraFacing('front')
设置相机预览的角度 0、90、180等等 //默认0
setDisplayOrientation
setDisplayOrientation(90)