Bluetooth file sharing without pairing - android

Is there a way to send files via bluetooth without pairing in android?

Here's a part of doc which I found here. RFCOMM channels is used here for bluetooth communications. This might help you in understanding that pairing is necessary.
paired means that two devices are aware of each other's existence,
have a shared link-key that can be used for authentication, and are
capable of establishing an encrypted connection with each other. To be
connected means that the devices currently share an RFCOMM channel and
are able to transmit data with each other. The current Android
Bluetooth API's require devices to be paired before an RFCOMM
connection can be established.
Again below,
If the two devices have not been previously paired, then the Android
framework will automatically show a pairing request notification or
dialog to the user during the connection procedure. So when attempting to connect devices, your application does not need to be concerned about whether or not the devices are paired. Your
RFCOMM connection attempt will block until the user has successfully
paired, or will fail if the user rejects pairing, or if pairing fails
or times out.

Related

Data lost while reading on Bluetooth rfcomm device

I have a Bluetooth device which is connected to Android smartphone over Bluetooth SPP profile.
Once connection is successful, device opens the rfcomm device
handle = open("/dev/rfcomm0", O_RDWR | O_NOCTTY | O_SYNC);
After successful connection smartphone sends data to device.
It sends 3 consecutive messages of few bytes to device. This is verified after looking at snoop log of Bluetooth device.
However the blocking read at Bluetooth device side is never able to read initial 2 messages, after that it reads all other messages.
Same experiment is tried by writing a standalone script which starts reading data on rfcomm device as soon as SPP connection is successful, but here also outcome is same.
Please guide what might go wrong.
More or less it was a timing issue.
The app on device requests Bluetooth stack to create SPP connection with Android phone. On successful SPP connection /dev/rfcomm0 device is created by Bluetooth stack.
As soon as rfcomm channel is created, Android phone sends data to device but by this time application on device was not updated with the creation of rfcomm device. As there are no readers for rfcomm, Bluetooth stack flushes all data it received from Android phone.
Performed this experiment multiple times, once it worked.

Can I connect bluetooth device automatically with the device which already paired without showing choose dialog

I am developing a solution for connection between OBD2(Vehicle ECU scanner) with the mobile app.
I want that when ever that OBD device is found and it is already paired then the application automatically connect with the device and create a socket for transmission of data . without showing the dialog box to choose a paired device.
You can connect to any paired Bluetooth device, to do so, you have to know device's address and UUID. Embedded devices may have some defined uuid (for example, hc05 adapter), you can get that uuid from documentation.
The tricky part here is that you have to monitor failure and loss of connection so you can retry again. I'm implementing that feature in my home project, fell free to see code: https://github.com/AlexShutov/LEDLights

Discovering Bluetooth Devices only for devices with a required application

I'm working on an android app where one user can connect to another person who has the same application, via Bluetooth connection. This peer-peer connection, only should allow persons with the same application to be able to discover your device and connect to it. Is it possible to 'mask' your device and only allow a device that has the same application that is being used for communication to discover your device?
As far as I know, this is not possible. As soon as you start advertising your device is visible to all bluetooth devices. You would need to implement an authentication after the connection was established and then drop the connection if a device cannot authenticate itself.

How does an android bluetooth insecure RFCOMM connection work under the hood

My understanding (which may very well be wrong) of Bluetooth is that in order to communicate, two Bluetooth devices must be part of a piconet.
To create a piconet the two devices perform pairing and choose a common radio channel to communicate on.
Android provides a way for two devices to communicate by using an insecure RFCOMM connection which does not require pairing.
Given that no common channel is agreed upon by the two devices, how are they able to exchange packets?
To quote the official Android BT specs:
Remember there is a difference between being paired and being
connected. To be paired means that two devices are aware of each
other's existence, have a shared link-key that can be used for
authentication, and are capable of establishing an encrypted
connection with each other. To be connected means that the devices
currently share an RFCOMM channel and are able to transmit data with
each other. The current Android Bluetooth API's require devices to be
paired before an RFCOMM connection can be established. (Pairing is
automatically performed when you initiate an encrypted connection with
the Bluetooth APIs.)
For RFCOMM under the hood, you should look in to the specifications of RFCOMM
The practical answer of Android insecure versus secure connections, is that the pairing (which is mandatory for Bluetooth v2.1 +) can be "unauthenticated" versus "authenticated". Basically, automatic pairing procedures create "unauthenticated" pairings, while user interactive pairing procedures create "authenticated" pairings. The Bluetooth connection is exactly the same for either. This is just a simple flag reflecting the type of pairing that occurred. Usually embedded devices, without keypads or displays, will have to use the "Just Works" automatic pairing method, and will generate an "unauthenticated" pairing.
Since Bluetooth v2.1, all connections must pair (except for legacy connections still supported), and the pairing scheme used is determined by the advertised IO capabilities of the two devices. There is a lookup table to determine: Just Works, Numeric Comparison, or Passkey Entry (different than legacy pin code).
PDF: Bluetooth Org Secure Simple Pairing (new pairing schemes) User Interface

Is there a way to isolate and control the Bluetooth pairing process programmatically in Android?

My applications connects my Android phone to a health device. The health device is capable of connecting using either Bluetooth SPP or HDP profile while my app can only support SPP.
The health device's documentation states that I have to send a special command to the it during the pairing process to make sure that Bluetooth communication uses SPP profile instead of HDP.
Note that I'm not concerned about connection after pairing at all. I need to:
Separate the pairing process from the connections after pairing - I don't mind if users have to authorise pairing through a popup
Be able to send some data to the health device during the pairing process (so that following connections will actually happen)
The Android documentation seems to imply that pairing is implicitly handled as an integrated part of the Bluetooth connections as you call connect() or accept(). However, this and this gives me some hope.
I'd like to support as many devices as possible but 4.0 and above are more important. The health device I'm using supports Bluetooth 2.1 so no worries about PIN.

Categories

Resources