我希望通过蓝牙接收图像并在图像视图中显示该图像。我知道如何将图像从一个活动传递到另一个活动,但我不知道如何使用蓝牙接收图像。
答案 0 :(得分:0)
Android框架通过Android蓝牙API提供对蓝牙功能的访问。这些API使应用程序可以无线连接到其他蓝牙设备,实现点对点和多点无线功能。
使用蓝牙API,Android应用程序可以执行以下操作:
创建BluetoothSocket并连接到它:
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(<your-device>.getUuids()[0].getUuid());
socket.connect();
收听套接字(从设备获取数据)
InputStream inStream = socket.getInputStream();
while (inStream.available() > 0) {
inStream.read(); // <-- data from device
}
写入套接字(将数据发送到设备)
OutputStream outStream = socket.getOutputStream();
byte[] bytes = <some-data>
outStream.write(bytes);
有关详细信息,请阅读Bluetooth Api Documentation here