Android bluetooth implementation basics

Can anyone explain in simple words to me the need for a UUID in the Android-bluetooth example. I read some articles about this, but it is still unclear if a UUID is needed. And now let me explain to you the scenario of what I want to develop: I want to develop an Android application for data transfer, for example, “FILE with the extension .xyz” from my phone to another phone via Bluetooth. IT IS NOT ALL REQUIRED THAT THE RECEIVED PHONE SHOULD HAVE AN APPLICATION THAT I AM USING. I just want to transfer data from my application to another phone, and that’s all. I don't care what the receiver does with the data. I just want to connect to a device within range and transfer this file using my application Now, how do I do this? Where is the UUID role here? I read that the UUID for my application, and both the server and the recipient, must know the UUID in order to form a connection. But what if the recipient does not have my application? He certainly does not know my UUID applications? how is data transfer possible? I just want to use Bluetooth without a specific application. Here, what should my application do? Should there be a server socket / client socket creation or what? and why.

A clear explanation in simple words (if possible, some articles). I don't want regular answers with BluetoothChat suggestions. If you do not understand the question, please let me know, I will try to be more specific and clarify it for you. The main purpose of this question is to clarify the use of UUIDs and transfer data between two DEVICES (rather than applications) using bluetooth from an application running on the same Android phone.

+6
source share
2 answers

Even with bluetooth, you can create a client server application .. there is a BluetoothSocket read here http://developer.android.com/reference/android/bluetooth/BluetoothSocket.html

Now, let's say you have two devices:

  • device A
  • device B

and suppose device A sending data to device B, you did not say that device B also sends data to device A, so I’ll just describe the first scenario when A sends B.

So, in this case, since all the data is stored in device A, and you want to send it to device B, it would be wiser to create device A as a Bluetooth server and device B as a BluetoothClient that listens to the server.

But .. If you want both devices to exchange data, you can make one of them as a server and 2 streams are created for each of them:

  • Subject sending data
  • a stream that listens for data

so that both of them can exchange data.

Another thing. If you have ever programmed a regular client server, you notice the accept() method, which locks until there is a client connected to the server. Same thing with the Bluetooth client-client application.

Summarize:

  • One device will act as a server - so you will need to write a server project and install it on the first device

  • The second device will act as a client - so you will need to write a client project and install it on the second device

  • Remember to add the Bluetooth permission to the manifest file for both projects.

  • Both projects need the same UUID as your question. In simple words, both parties need a UUID so that each of them knows who they are talking to. I think this is more like a port on a regular client server. I read somewhere that it is used for RFC communication .. as you probably know, there are some protocols for Bluetooth, such as RFC, SDP, etc.

EDIT: Most phones have a pairing process when you want to send data via Bluethooth. so if you do not want to use the client-server version, I think you can do the following:

  • Your application will search for devices to connect. (pairing process)
  • After pairing, you connect to another device and simply send data

EDIT 2: Do you want to send data from A to B to the right? I will explain more clearly.

You are right when you say that the client needs to know who the server is, and you need to insert the port and the IP address of the server is correct and works this way.

Now take a look.

The server listens for a connection with clients when a connection has been established.

  • Customer requests data
  • The server processes the client request and sends it the corresponding data.

    Thus, any data, such as: Files, databases should be stored on the server side.

    Now, in your case, the files you want to send are in device A, and not in device B. Therefore, if device A is a server, it will listen for connections .. when device B connects to the server (device A), communication begins. Device B can request files from device A .. In addition, since device A is a server, it can even broadcast a message .. means to send the same message to all clients associated with it.

    But what you want to do is send the file even if device b did not request it, right? I don’t understand if you want device B to also send the file to device A, so we’ll split it into
    in the script:

  • just send device A to B: In this case, since the files are in device A, it means that device A has data, device A is the server, and device B is the client. Therefore, when the connection is established, you can send from A to B.

  • Both devices communicate: In this case, both devices must listen to each other, but only one of them must act as a server and the other as a client. means that you need to install serverApp one of them and clientApp on the other. But each of them can send and listen to others. therefore, for each of them you need to create a stream that processes the transmitted data and another stream that processes the received data.

+5
source

UUID is a universal unique identifier. If you want to connect to any service that bluetooth provides, you must have a UUID in order to tell the bluetooth software module that it should initiate a connection to this particular service. In your case, to send a file from DevA to DevB, it must use a file transfer profile, and a certain uuid is associated with it, and this is determined by Bluetooth SIG, which is the authority that qualifies Bluetooth products and works on the technology. This is known to all devices using bluetooth.

We’ll briefly tell the story when DevB receives a request for an incoming request with a unique identifier uuid, to which it finds out which particular DevB service the device is trying to connect to and connect to this service. Therefore, if you want to send a file from DevA to DevB, you do not need to have one application in DevB. But you need to make sure that you are using the UUID that is specified for the file transfer profile using Bluetooth SIG.

Regards, Shripathi

+1
source

Source: https://habr.com/ru/post/944273/


All Articles