bluetooth.axml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <view class="page">
  2. <view class="page-description">蓝牙 API</view>
  3. <view class="page-section">
  4. <view class="page-section-title">本机蓝牙开关状态</view>
  5. <view class="page-section-demo">
  6. <button type="primary" onTap="openBluetoothAdapter">初始化蓝牙</button>
  7. <button type="primary" onTap="closeBluetoothAdapter">关闭本机蓝牙</button>
  8. <button type="primary" onTap="getBluetoothAdapterState">获取蓝牙状态</button>
  9. </view>
  10. <view class="page-section-title">扫描蓝牙设备</view>
  11. <view class="page-section-demo">
  12. <button type="primary" onTap="startBluetoothDevicesDiscovery">开始搜索</button>
  13. <button type="primary" onTap="getBluetoothDevices">所有搜索到的设备</button>
  14. <button type="primary" onTap="getConnectedBluetoothDevices">所有已连接的设备</button>
  15. <button type="primary" onTap="stopBluetoothDevicesDiscovery">停止搜索</button>
  16. </view>
  17. <view class="page-section-title">连接设备</view>
  18. <view class="page-section-demo">
  19. <input class="input" onInput="bindKeyInput" type="{{text}}" placeholder="输入要连接的设备的deviceId"></input>
  20. <button type="primary" onTap="connectBLEDevice">连接设备</button>
  21. <button type="primary" onTap="getBLEDeviceServices">获取设备服务</button>
  22. <button type="primary" onTap="getBLEDeviceCharacteristics">获取读写特征</button>
  23. <button type="primary" onTap="disconnectBLEDevice">断开设备连接</button>
  24. </view>
  25. <view class="page-section-title">读写数据</view>
  26. <view class="page-section-demo">
  27. <button type="primary" onTap="notifyBLECharacteristicValueChange">监听特征值数据变化</button>
  28. <button type="primary" onTap="readBLECharacteristicValue">读取数据</button>
  29. <button type="primary" onTap="writeBLECharacteristicValue">写入数据</button>
  30. <button type="primary" onTap="offBLECharacteristicValueChange">取消特征值监听</button>
  31. </view>
  32. <view class="page-section-title">其他事件</view>
  33. <view class="page-section-demo">
  34. <button type="primary" onTap="bluetoothAdapterStateChange">本机蓝牙状态变化</button>
  35. <button type="primary" onTap="offBluetoothAdapterStateChange">取消本机蓝牙状态监听</button>
  36. <button type="primary" onTap="BLEConnectionStateChanged">蓝牙连接状态变化</button>
  37. <button type="primary" onTap="offBLEConnectionStateChanged">取消蓝牙连接状态监听</button>
  38. </view>
  39. </view>
  40. </view>