更新记录

1.0.3(2024-07-17)

优化

1.0.2(2024-06-28)

优化

1.0.0(2024-05-14)

初版

查看更多

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.6.8,Android:支持,iOS:不确定,HarmonyNext:不确定 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

jk-ble

开发文档

<template>
    <view class="content">
        <button @click="onGrant">onGrant</button>
        <button @click="onInit">onInit</button>
        <view style="display: flex;flex-direction: row;">
            <button @click="onScan">Scan</button>
            <button @click="onStopScan">StopScan</button>
        </view>

        <view style="display: flex;flex-direction: row;">
            <button @click="connect">connect</button>
            <button @click="disconnect">disconnect</button>
            <button @click="connState">connState</button>
        </view>
        <button @click="notify">notify</button>
        <button @click="write">write</button>
    </view>
</template>

<script>
    import * as JkBLE from "@/uni_modules/jk-ble";
    export default {
        data() {
            return {
                characteristic: null,
                deviceId: '----'
            }
        },
        onLoad() {
            JkBLE.onBluetoothDeviceFound((device : BluetoothDeviceFoundResult) => {
            });
            JkBLE.onBLEConnectionStateChange((result : BLEConnectionStateChange) => {
            })
            JkBLE.onBLECharacteristicValueChange((result : BLECharacteristicValueChange) => {
                let datas = result?.value
                if (datas != null) {
                    let list : string[] = []
                    datas.forEach(item => {
                        list.push(number2Int(item).toString(16))
                    })
                    console.log("recv:" + list)
                }
            })

        },
        methods: {
            onGrant() {
                let permission = JkBLE.blueToothPermissions()
                if (permission != null) {
                    UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permission, (_ : boolean, p : string[]) => {
                    }, (_ : boolean, p : string[]) => {
                    })
                }
            },
            onInit() {
                JkBLE.debugEnable()
                JkBLE.initBLE()
                JkBLE.openBluetoothAdapter()
            },
            onScan() {
                JkBLE.startBluetoothDevicesDiscovery({
                    success: () => {
                    },
                } as BluetoothDevicesDiscoveryOptions)
            },
            onStopScan() {
                JkBLE.stopBluetoothDevicesDiscovery()
            },
            connect() {
                let deviceId = this.deviceId
                JkBLE.createBLEConnection(deviceId)
            },
            disconnect() {
                let deviceId = this.deviceId
                JkBLE.closeBLEConnection(deviceId)
            },
            connState() {
                let deviceId = this.deviceId
                console.log(("connected:" + JkBLE.isBLEConnected(deviceId)))
            },
            notify() {
                let deviceId = this.deviceId
                let options : NotifyBLECharacteristicValue = {
                    deviceId,
                    autoFind: true,
                    success(characteristic) {

                    }
                }
                JkBLE.notifyBLECharacteristicValueChange(options)
            },
            write() {
                let deviceId = this.deviceId
                let datas = [1,2,3]
                if (this.characteristic != null) {
                    JkBLE.writeBLECharacteristicValue(deviceId, this.characteristic, datas)
                }
            }

        }
    }
</script>

<style>
    .content {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 200rpx;
        margin-bottom: 50rpx;
    }

    .title {
        font-size: 36rpx;
        color: #8f8f94;
    }
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- If your app targets Android 9 or lower, you can declare ACCESS_COARSE_LOCATION instead. --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问