Android BT Handover AND Start App - android

I'm trying to do several things at once with a single NDEF message on a tag, and I'm starting to wonder if Android actually supports what I want to do.
When I touch the phone to the tag, I want to
Start my application
Configure my application with the MAC address of a bluetooth device stored in the tag.
Pair the bluetooth device with minimal user interaction
Open a BluetoothSocket from my application to the bluetooth device.
To this end, I've created an NDEF message (I've heard android only supports 1 message), with several NDEF records.
The first is a URI record for my company's website, and I've registered an intent filter in my app to be able to catch this record.
The second is a Handover Select record containing the bluetooth mac address of a device, and randomized C and R values.
The third is an AAR record specifying my application package.
So on to the problems:
If I put the handover select record first, Android will silently pair (GOOD!) and attempt to connect to the target device (BAD!), without ever notifying my application (BAD!)
If I put the URI record first, Android will notify my activity with all the bytes on the tag (GOOD!) but I have no way to silently pair (BAD!) or make use of the randomized numbers in the Handover Select record (BAD!). I don't see any obvious way to re-fire the Handover Select record so another activity can handle the pairing (BAD!)
In a perfect world, it would silently pair bluetooth, and notify my app so I can connect to the remote device. Is there any way I can do this?

Related

Android multiple apps listen to same bluetooth connection

Let's say we have 2 bluetooth devices, 1 is some device that emits data and the other one is an Android device. Now in the android device, there will be more than 1 app that may run at the same time and would like to listen to that bluetooth connection and process the data received. Is this possible? Or any restriction?
Assuming you're talking about official, non root android firmwares: no you cannot share memory locations assigned to your application variables(in your case a bluetooth socket inputstream) with other applications.
You can however create one bluetooth client connection in one app, receive the data and then share the data with other applications or services using network sockets or named pipes or files...;

Android app to send and receive a file automatically when get connected via bluetooth

I am new to android world.I want to design an android app in which all connections will be through bluetooth. It will works as follows
as I click some button like start it will connect to one of the paired devices(mobile) and get a file, store it somewhere and eventually disconnect with that device.Then it will connect to the second device, get a file, store it and then disconnect with that device and so on. It will repeat the same procedure for all the paired devices.
And later on I will replace those paired mobiles with sensors and will collect the the data.The whole process should be automatic without user's intervention.
Guys please help me. Is it possible for a mobile to send a file automatically as it connects to a particular mobile.

android send files over bluetooth without pairing

There's a way I can send a file to an android device (wich already has my app installed) without paring or the app making the pairing in the background? (Without user intervention)
In my country just few people have data plans in their phones, so I want to create some kind of "server" using a raspberry and a bluetooth dongle so everytime an user with my app it's inside my store, I can show them notifications (with images and text) using the bluetooth connection insted of their cellphone data. (To detect they are in my store I can use geofences or regular beacons)
BLE is not intended to send files with huge size, since it can maximally send 20 byte chunks of data at a time. I'll definately go for the standard Bluetooth protocol if you have a file consisting of a huge size.
The pairing notification depends on how the app has been developed. If you know the device address (MAC address as unique ID) of the remote device beforehand, then you can make a simple "if" statement that checks whether the device address of each discovered device equals the one you have defined. If yes, then you can establish a connection. As a result, the app will automatically establish a connection with the desired device.

android bluetooth implementation basics

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.
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:
device A
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:
Thread that sends data
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:
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:
Your application will search for devices to connect to. (pairing process)
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.
Client ask for data
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
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

Android NFC p2p to retrieve information

I was reading about Near Field Communication on Android and was wondering if there is any way to retrieve information from one phone by another. So this can be done in two ways :
Phone(Retriever) connects via NFC to another Phone(Client). The Client does not have any special application installed, but we have an application installed in the Retriever. The Retriever then fires a query and can it get some information about the Client device(say the owners email address)? (Remember no special application is installed in the Client phone).
In this scenario the Client has an appropriate application installed that captures the NFC query, parses it, retrieves the relevant data from the Client and sends back an NFC message to the Retriever.
My background research says that it should be possible through the second way. I have two questions:
1.Is it possible through the first method. If yes then how?
2.Could you suggest me some good tutorial for the second method
Both scenarios are currently not possible with Android devices. Android apps on devices with NFC can push data via NFC to another device. There is no way to query and retrieve information (pull data) via NFC on Android.
With NFC tags, the Android device acts as a card reader/writer device. In that case the Android device can interrogate the tag and retrieve information from it.
From my experience both devices must have an app that is reade to receive a NFC event, the "caller" must have the application in foreground, when it gets close to other device, the "beam" appears and the NdefMessage is sent, on the receiver each application that has an intent filter for that MIME-TYPE can get launched and process the nfc event.
The reference as a starting point is this and the project sample from the API.

Categories

Resources