- 蓝牙通信方式
- 经典蓝牙(Bluetooth Classic)通信:
- 经典蓝牙通信通常用于在较短的距离内传输大量数据,例如音频流、文件传输等。
- 在 Android 中,你可以使用 BluetoothAdapter 和 BluetoothSocket 类来建立经典蓝牙连接,并进行数据传输。
- 经典蓝牙通信通常需要进行配对和授权,以确保通信的安全性。
- 蓝牙低功耗(Bluetooth Low Energy,BLE)通信:
- BLE 通信适用于低功耗设备和周期性数据传输场景,例如健康监测、传感器数据采集等。
- 在 Android 中,BLE 通信通常使用 BluetoothLeScanner 和 BluetoothGatt 类来实现。
- BLE 通信不需要配对,通常以连接为基础,并且支持广播、订阅通知等特性。
- 经典蓝牙(Bluetooth Classic)通信:
权限适配参考
https://juejin.cn/post/7320169878644031488
https://www.cnblogs.com/fly263/p/16715525.html
https://blog.csdn.net/qq_17189617/article/details/135291784
流写数据
https://cloud.tencent.com.cn/developer/article/2310635
https://www.jb51.net/article/263206.htm
* 客户端设置* 单击事件* */@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {String s = arrayAdapter.getItem(position);String address = s.substring(s.indexOf(":") + 1).trim();//获取蓝牙IPtry {if (bluetoothAdapter.isDiscovering()) {bluetoothAdapter.cancelDiscovery();//若当前蓝牙被使用,则关闭重新启用}try {if (device == null) {//若未连接,则获得远程设备device = bluetoothAdapter.getRemoteDevice(address);}if (clientSocket == null) {clientSocket = device.createRfcommSocketToServiceRecord(MY_UUID);clientSocket.connect();//连接蓝牙os = clientSocket.getOutputStream();//客户端向服务端输出文本}} catch (IOException e) {e.printStackTrace();}if (os != null) {os.write("发送信息到其他设备".getBytes("utf-8"));}} catch (Exception e) {e.printStackTrace();}}
https://www.cnblogs.com/Free-Thinker/p/11507349.html
读写特征判断
https://blog.51cto.com/u_16213401/9599749