6

can anyone in simple words explain me the need of UUID in android bluetooth example. I have read some articles about it but it is still not getting clear the exact need of UUID. And now let me explain you the scenario of what I want to develop: I want to develop an android application to transfer data for example a "FILE with .xyz extension" from my phone to the other phone over bluetooth. IT IS NOT AT ALL NECESSARY THAT THE RECEIVING PHONE SHOULD ALSO HAVE THE APPLICATION THAT I AM USING. I just want to transfer data from my application to other phone and thats it. I don't care what the receiver does with the data. I just want to connect to a device within range and transfer that file using my application Now how should I do this? Where does the the role of UUID come here? I have read that UUID is for my application , and both the server and the receiver should be aware of this UUID to form a connection . But what if the receiver does not have the my application? It will surely not know my Applications UUID ? then how the data transfer will be possible? I simply want to use Bluetooth without concerning a specific application. In here, what my application should be doing? Should it be creating a server socket / a client socket or what? and Why.

An explanation in simple words is appreciated(some articles if possible). I dont want regular answers having BluetoothChat suggestions. If you don't understand the question please let me know, I will try to be more specific and elaborate it for you. The basic goal of this question is to clarify the use of UUID and transfer data between two DEVICES (and not an application) using bluetooth from an application running on one android phone.

user2056245
  • 595
  • 1
  • 9
  • 24

2 Answers2

5

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, lets say you have two devices:

  1. device A
  2. device B

and assume that device A sending data to device B, You didn't say if device B is also sending data to device A, so I'll just describe the first scenario when A send to B.

So in that case, since all the data is stored in device A and you want to send it to device B, it will be more reasonable to create device A as a BluetoothServer and device B as BluetoothClient which listening to the server.

But.. If you want both of devices will exchange data.. you can make one of them as a server and for each one of them create 2 threads:

  1. Thread that sends data
  2. thread that listening to data

so both of them can exchange data..

Another thing.. if you ever programmed a regular client server you noticed the accept() method which is blocking until there is a client which connected to server.. the same is with Bluetooth client-server application.

Summarize:

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

  2. Second device will act as a client - so you'll need to write a client project and install it on the second device

  3. Don't forget to add the bluetooth permission in the manifest file for both
    projects.

  4. Both of the projects need the same UUID as you mentioned in your question. in simple words both of the sides need the UUID so they each know with who they're communicate I think it's more like a port in a regular client-server.. I read somewhere that is used for RFC communication.. as you probably know there are
    some protocols for Bluetooth like RFC,SDP and etc..

EDIT: In most of the phones there is a pairing process when you want to send data through bluethooth. so if you don't want to use the client-server version, I think you can do this:

  1. Your application will search for devices to connect to. (pairing process)
  2. After pairing you are connected to the other device and just send the data

EDIT 2: You want to send data from A to B right? I'll explain more clearly..

You're right when you said the client should know who is the server and need insert the port and the IP of the server this is correct and works in this way.

Now, look..

The server listen to connection from clients, when a connection established the communication begins.

  1. Client ask for data
  2. The server processing the client request and send him the related data

    So any data like: Files, Databases should be stored on the server side..

    Now in your case, the files you want to send are located in device A and not in device B, So if device A is the server he will listen for connections.. when device B connects to the server (device A) the communication begins.. Device B can request for files from Device A.. Also, since device A is the server, he can even broadcast a message.. means send the same message for all clients which are connected to him.

    But what you're want to do is to send file even if device b didn't ask for it, right? I don't understand if you want that device B will also send file to device A, so lets divide it
    into scenarios:

  3. just device A send to B: In this case, since the files are located in device A, means device A have the data, device A is the server and device B is the client. So when connection established you can send from A to B.

  4. Both devices exchange data: In this case, both devices should listen to each other, but just one of the should act as a server and the other as a client. means that you need to install the serverApp on one of them and the clientApp on the other. But each of them can send and listen to other. so for each of the you need to create thread that handle with the sending data and another thread that handles the receiving data

Elior
  • 3,178
  • 6
  • 37
  • 67
  • So my question is if we meet tomorrow for the first time and I have my application running on my device and (obviously you wont be having it on your ) and I want to send that ".xyz" file to you using bluetooth , I wont be able to send? – user2056245 May 04 '13 at 09:33
  • I will only be able to send if YOU have my application on YOUR phone? – user2056245 May 04 '13 at 09:34
  • For time being , its just me who wants to send data to YOU using my application and you (your phone) having no idea of what application I am using and what data I am going to send? Is this possible? – user2056245 May 04 '13 at 09:38
  • No I don't think it will work.. but maybe you can do a pairing so your app will search for devices with bluetooth and ask to connect them and then send the data – Elior May 04 '13 at 09:41
  • you're welcome , have a look at those links for pairing devices http://stackoverflow.com/questions/14228289/android-device-bluetooth-pairing http://stackoverflow.com/questions/4989902/how-to-programmatically-pair-a-bluetooth-device-on-android – Elior May 04 '13 at 12:36
  • Sir , I think I am not able to understand your suggestion "it will be more reasonable to create device A as a BluetoothServer and device B as BluetoothClient which listening to the server. " As per my knowledge, Client device should have knowledge of the the server device to which it wants to form the connection. So the sending side (dev A) will know that it wants to send to B. But B will not be knowing of A. As it just wants to accept data. So I think B should become the server and A the client? because A knows that B is present , B doesnt know A is present. So wont it be better to connect.. – user2056245 May 05 '13 at 11:20
  • A to B i.e to make A the client and C the server (waiting to receive the data ) ? – user2056245 May 05 '13 at 11:20
  • thankyou very much!! so i should first pair with the desired device and then send the data..... and for that i should follow the your first comment ..... pairing will completely eliminate the client/server thing ?? – user2056245 May 05 '13 at 11:56
  • and one more question, uuid will be required anyhow?? for pairing as well as client/server? – user2056245 May 05 '13 at 11:56
  • I don't know why you want to create this without client-server side, but it will be more easier.. take a look at this http://developer.android.com/guide/topics/connectivity/bluetooth.html and I think you will need the UUID in both ways – Elior May 05 '13 at 12:17
  • no no ...its just that I want find out different ways of doing it.... and implement the easiest way in my project..... what would you prefer ? At present I am implementing the client/server as you explained.... in further versions I may try the other method You pointed out if it seems better – user2056245 May 05 '13 at 12:57
  • Sir, I think I am totally missing at some point.... I think my concepts are not clear or have less knowledge or not able to completely understand what you are explaining me...... I am facing problem to understand, how "B" will be able to connect to "A" if he does not have any prior knowledge of "A being there" ? I totally agree if A becomes the server he will be able to connect to multiple clients.. so how should I do that? Do You mean to say "B" should start its bluetooth, start discovery , find A (which is the server) and then the data transfer should proceed ? – user2056245 May 05 '13 at 13:18
  • Yes, like regular client server, when you have a Server, the server waits for client connections.. and for each client he create a HandleThread.. in this case the client need to know the port and the IP address of the server. In your case, side A should always turn on the bluetooth and wait for client connection.. side B should search for bluetooth device (in this case he will search for A) and ask for connect.. now A should accept the connection – Elior May 05 '13 at 14:38
  • at the developer side they show you how to implement the server side, and how to implement the client side.. try to use it for exapmle – Elior May 05 '13 at 14:39
  • @Elior This very clearly written in the Question that the user2056245 dont want any client server arch. You answer is pointing to the same concept of popular Bluetooth chat application: https://github.com/googlesamples/android-BluetoothChat So question is to send the file to some unknown Bluetooth device (Mac, PC or android phone) where my application is not running. There are such apps who do such implementation like: https://play.google.com/store/apps/details?id=it.medieval.blueftp&hl=ru They Use OBEX protocol which is standard for bluetooth communication. – Gem Dec 21 '16 at 19:35
1

UUID is the Universal Unique Identifier. When you want to connect to any of the service that bluetooth is exposing then you should have the UUID to tell to the bluetooth software module that it has to inititae connection to this particular service. In your case in order to send file from DevA to DevB it has to use File Transfer Profile and there is specific uuid which is associated with this and this is defined by Bluetooth SIG which is the authority which qualifies bluetooth products and works on the technology. This is known by all the devices which uses bluetooth.

Tu cut the story in short when DevB receives the incoming connection request with the uuid which is unique it comes to know to which particular service of DevB the device is trying to connect to and it connects to that service. Hence if you want to send file from DevA to DevB then you need not have the same application at DevB. But you need to make sure that you use the UUID which is specified for File Transfer profile by Bluetooth SIG.

Regards, Shripathi