I'm back from holidays... but during it, I did something on my tethering indicator project.
It was thinked as a simple application.. and now it is no-more a pure simple activity that talks with bluetooth..but something more complex.
The apps on the phone, is composed by 2 part:
- a service that make available data through bluetooth and show a notification whenever it is started.
- an activity that talks to the previous service for control and send command like: start/stop service.
It was not easy to understand how to make the activity bind and unbind correctly from the service, also when the activity die, but after some test and research I did it.
This is a simplified diagram of the actual architecture :
I didn't released the code now, but I will do very soon, at least for the android server, when it will be enough good.
For now the program on the phone works.
Tuesday, 21 August 2012
Tethering Indicator: start simple grow complex
Thursday, 2 August 2012
A Bluetooth Server on Android: part 2, the code
From the previous post
Summary for a bluetooth server:
- Turn the bluetooth chip on
- Be visible to others
- Create a Service
- Listen for incoming connection
The methoed for realize the previous steps are in these methoeds extracted by the code of TetheringIndicator.
Summary for a bluetooth server:
- Turn the bluetooth chip on
- Be visible to others
- Create a Service
- Listen for incoming connection
The methoed for realize the previous steps are in these methoeds extracted by the code of TetheringIndicator.
Wednesday, 1 August 2012
A Bluetooth Server on Android: part 1
This is the first of 2 posts on "How to make your Android Phone, listen for remote request with bluetooth".
Bluetooth is a mature tecnology used everywhere.
For my experience, it is not an easy tecnology to manage, if you want to simply share something you have to follow many steps.
If you are a developer and you want to simply create a connection and pass data between 2 devices (whatever the devices are), you have to create a lot of code and first of all, learn how this tecnology works.
As a reference platform in this post I will use Android; things can change from a platform to another but the key concept are the same.
Who are you? Be visible!
Bluetooth have differents modes:
So the first things you have to do, in a bluetooth server are:
On Android, whenever you try to make your bluetooth phone on or visible, a system dialog message, automatically advise the user of the action.
The 3rd step is available only for a limited amout of time (you can specify how many seconds)... I think this is just for security and autonomy reason.
What do you offer? A service
Be visible is not enough to establish a connection with another device.
You have to specify the services that you are offering.
A service is a way to declare what you are capable to offer in term of data, for another device.
It is what you expose to others.
Every phone have some default service created for sharing content like calendar, phonebook etc...
A service is identified by a name and a UUID: http://en.wikipedia.org/wiki/Universally_unique_identifier.
How do we talk? With a profile
A profile is a low level bluetooth protocol that explain which type of message and communication you are trying to establish.
Bluetooth is used in different way so you have different profile specific for a task: there is A2DP for bluetooth audio communication (used by bluetooth earphone), Obex for file transfers, L2Cap for exchange information, RfComm is a sort of serial communication over bluetooth and others profiles.
When you have to make 2 device talk eachother with your own protocol, the options are usually use L2Cap or RfComm and built your protocol on top of them.
I have decided to use RfComm.
Summary for a bluetooth server:
- Turn the bluetooth chip on
- Be visible to others
- Create a Service
- Listen for incoming connection
Next:
The android code will be explained and available in the next post on the blog.
Bluetooth is a mature tecnology used everywhere.
For my experience, it is not an easy tecnology to manage, if you want to simply share something you have to follow many steps.
If you are a developer and you want to simply create a connection and pass data between 2 devices (whatever the devices are), you have to create a lot of code and first of all, learn how this tecnology works.
As a reference platform in this post I will use Android; things can change from a platform to another but the key concept are the same.
Who are you? Be visible!
- visible: any other device around that start a bluetooth search, Inquiry, will find the device.
- not visible: you can see other device around you, but none can see you in a search and establish a connection.
- off: the chip is off.
So the first things you have to do, in a bluetooth server are:
- get a reference to your internal bluetooth chip
- set the chip on
- set chip in visible mode
On Android, whenever you try to make your bluetooth phone on or visible, a system dialog message, automatically advise the user of the action.
The 3rd step is available only for a limited amout of time (you can specify how many seconds)... I think this is just for security and autonomy reason.
What do you offer? A service
Be visible is not enough to establish a connection with another device.
You have to specify the services that you are offering.
It is what you expose to others.
Every phone have some default service created for sharing content like calendar, phonebook etc...
A service is identified by a name and a UUID: http://en.wikipedia.org/wiki/Universally_unique_identifier.
How do we talk? With a profile
A profile is a low level bluetooth protocol that explain which type of message and communication you are trying to establish.
Bluetooth is used in different way so you have different profile specific for a task: there is A2DP for bluetooth audio communication (used by bluetooth earphone), Obex for file transfers, L2Cap for exchange information, RfComm is a sort of serial communication over bluetooth and others profiles.
When you have to make 2 device talk eachother with your own protocol, the options are usually use L2Cap or RfComm and built your protocol on top of them.
I have decided to use RfComm.
Summary for a bluetooth server:
- Turn the bluetooth chip on
- Be visible to others
- Create a Service
- Listen for incoming connection
Next:
The android code will be explained and available in the next post on the blog.
Subscribe to:
Posts (Atom)