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.
What is Bluetooth? Bluetooth technology allows devices to communicate with each other without cables or wires. Bluetooth relies on short-range radio frequency, and any device that incorporates the technology can communicate as long as it is within the required distance.
In order to enable the Bluetooth of your device, call the intent with the following Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is. Intent turnOn = new Intent(BluetoothAdapter. ACTION_REQUEST_ENABLE); startActivityForResult(turnOn, 0);
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:
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:
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:
One device will act as a server - so you'll need to write a server project and install
it on the first device
Second device will act as a client - so you'll need to write a client project and install it on the second device
Don't forget to add the bluetooth permission in the manifest file for both
projects.
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:
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.
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:
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With