我知道如何通过调用手机本地蓝牙设置并让用户选择发送对象来发送文件。
但是假设我想直接将字符“v”发送到已配对的设备。我知道设备的名称和地址。最好的方法是什么?
private void sendDataToPairedDevice(String message ,BluetoothDevice device){
byte[] toSend = message.getBytes();
try {
UUID applicationUUID = UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(applicationUUID);
OutputStream mmOutStream = socket.getOutputStream();
mmOutStream.write(toSend);
// Your Data is sent to BT connected paired device ENJOY.
} catch (IOException e) {
Log.e(TAG, "Exception during write", e);
}
}
sendDataToPairedDevice("text to send" ,bluetoothDevice);
这就是全部内容。谢谢,伙计们享受。