How to receive images via Bluetooth

允我心安 提交于 2020-01-07 08:36:10

问题


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.


回答1:


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.

Using the Bluetooth APIs, an Android application can perform the following:

  • Scan for other Bluetooth devices
  • Query the local Bluetooth adapter for paired Bluetooth devices
  • Establish RFCOMM channels
  • Connect to other devices through service discovery
  • Transfer data to and from other devices
  • Manage multiple connections

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);

and for more details you can read Bluetooth Api Documentation here



来源:https://stackoverflow.com/questions/43930776/how-to-receive-images-via-bluetooth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!