/**
* 一、打开手机蓝牙功能
*/
let main = plus.android.runtimeMainActivity();
let Intent = plus.android.importClass("android.content.Intent");
let mIntent = new Intent('android.settings.BLUETOOTH_SETTINGS');
main.startActivity(mIntent);
/**
* 二、打开手机蓝牙功能
*/
const remindOpenBlueTooth = () => {
if (system.platform == 'android') {
const BluetoothAdapter = plus.android.importClass('android.bluetooth.BluetoothAdapter'); // 引入Java 蓝牙类
const blueadapter = BluetoothAdapter.getDefaultAdapter(); //拿到默认蓝牙适配器方法
if (blueadapter) {
// 判断蓝牙是否开启
if (blueadapter.isEnabled()) {
// 已开启
uni.showToast({
title: '蓝牙已打开',
})
} else {
// 未开启弹出提示框
uni.showModal({
title: '提示',
content: '蓝牙尚未打开,是否打开蓝牙',
showCancel: true,
cancelText: '取消',
confirmText: '确定',
success(res) {
// 点击确定后通过系统打开蓝牙
if (res.confirm) {
const blueadapter = BluetoothAdapter.getDefaultAdapter();
if (blueadapter != null) {
return blueadapter.enable();
}
} else {
// 点击取消什么也不做
console.log("点击了取消");
}
}
})
}
}
} else {
uni.showModal({
title: '提示',
content: '蓝牙尚未打开,请打开蓝牙',
showCancel: false,
confirmText: '确定',
success(res) {
}
})
}
}
uniapp安卓打开系统蓝牙
最新推荐文章于 2025-03-28 09:56:45 发布