如何通过蓝牙接收图像 [英] How to receive images via Bluetooth
问题描述
我想通过蓝牙接收图像并在图像视图"中显示该图像.我知道如何将图像从一个活动传递到另一活动,但是我不知道如何使用蓝牙接收图像.
I want to receive images via Bluetooth and display that image in Image View.I know how to pass image from one activity to another activity but i don't no how to receive images using Bluetooth.
推荐答案
Android框架通过Android蓝牙API提供对蓝牙功能的访问.这些API使应用程序可以无线连接到其他蓝牙设备,从而实现点对点和多点无线功能.
Android framework provides access to the Bluetooth functionality through the Android Bluetooth APIs. These APIs let applications wirelessly connect to other Bluetooth devices, enabling point-to-point and multipoint wireless features.
使用蓝牙API,Android应用程序可以执行以下操作:
Using the Bluetooth APIs, an Android application can perform the following:
- 扫描其他蓝牙设备
- 在本地蓝牙适配器中查询已配对的蓝牙设备
- 建立RFCOMM频道
- 通过服务发现连接到其他设备
- 与其他设备之间传输数据
- 管理多个连接
创建一个BluetoothSocket并连接到它:
Create a BluetoothSocket and connect to it:
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(<your-device>.getUuids()[0].getUuid());
socket.connect();
听套接字(从设备获取数据)
Listen to the socket (Get data from the device)
InputStream inStream = socket.getInputStream();
while (inStream.available() > 0) {
inStream.read(); // <-- data from device
}
写入套接字(将数据发送到设备)
Write to the socket (Send data to the device)
OutputStream outStream = socket.getOutputStream();
byte[] bytes = <some-data>
outStream.write(bytes);
,有关更多详细信息,请阅读此处的蓝牙Api文档
and for more details you can read Bluetooth Api Documentation here
这篇关于如何通过蓝牙接收图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!