[英]Sending character via bluetooth on Android?
I know how to send files by invoking the phone's native bluetooth settings and letting the user choose who to send to. 我知道如何通过调用手机的本机蓝牙设置并让用户选择发送给谁的方式来发送文件。
But let's say I want to send the character 'v' directly to a paired device. 但是,假设我要直接将字符“ v”发送到配对的设备。 I know the device's name, and address.
我知道设备的名称和地址。 What is the best way to go about doing this?
这样做的最佳方法是什么?
You can do it in this way: 您可以通过以下方式进行操作:
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);
}
}
Now Call above method like 现在调用像上面的方法
sendDataToPairedDevice("text to send" ,bluetoothDevice);
thats it. 而已。 thanks, enjoy buddy.
谢谢,哥们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.