钟铮锁App web部分 需要打包放进对应的安卓项目 生成apk 才能正常使用功能
he wei
2025-01-19 ba2cfa9907623c094e6e2d52d12dc3055ddd587a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { BluetoothLe } from '@ionic-native/bluetooth-le';
 
export class MyClass {
 
  constructor(bluetoothLe) {
    this.bluetoothLe = bluetoothLe;
  }
 
  // 扫描蓝牙设备
  scanDevices() {
    this.bluetoothLe.startScan().subscribe(device => {
      console.log(device);
    }, error => {
      console.log('扫描失败', error);
    });
  }
 
  // 连接到蓝牙设备
  connectDevice(device) {
    this.bluetoothLe.connect(device.id).subscribe(success => {
      console.log('连接成功');
    }, error => {
      console.log('连接失败', error);
    });
  }
 
  // 读取数据
  readData() {
    this.bluetoothLe.read().subscribe(data => {
      console.log(data);
    }, error => {
      console.log('读取数据失败', error);
    });
  }
 
  // 发送数据
  writeData(data) {
    this.bluetoothLe.write(data).then(success => {
      console.log('发送成功');
    }, error => {
      console.log('发送失败', error);
    });
  }
}