Android things pairing with BLE - android

I have a raspi3 with android things on it and I want to connect to a BLE device that requires a user authentication for bounding.
On a phone, after having set a characteristic on the BLE device, I am able to receive the Broadcast event
BluetoothDevice.ACTION_PAIRING_REQUEST
and in the meantime a dialog from android system opens asking me to accept the bluetooth connection (it has pairing variant = 3 (PAIRING_VARIANT_CONSENT)). When I accept it on the dialog everything goes nice and I connect to the device.
In my android things device I don't receive any ACTION_PAIRING_REQUEST event and my connection drops as soon as I write the characteristic on the BLE device.
Is there any way to have the accept process on android things?

You can use the Android Things BluetoothConnectionManager to initiate device pairing or respond to incoming pairing requests with a BluetoothPairingCallback. See the Bluetooth API guide for more details on device pairing.

Related

Is Bonding required for BLE <-> Android, iOS device communication?

We have a BLE device and android/ios app for communication with the device.
The requirement is to have an android/ios app connect to the device without any pairing request. No security is required on the device.
Hereafter a few questions around this:
Q1. Is it possible at all to have an android/ios app connect to a BLE
device without a pairing request?
Q2. Does the bonding required for
the BLE communication?
Q3. What is the downside of having the device
with no bonding? Is it going to drop the connection while the app is
running?
Q4. Who is the initiator or pairing dialog, the app, or the
device?
Q5. When having the device with Just Works security protocol,
with no bonding and no MITM protection, should we see a pairing
dialog?
Please see answers to your questions below:-
A1. Yes it is possible to do this because pairing and connection are two separate actions. Connection is when you establish a communication channel with a remote device, while pairing is when you exchange security keys with the device and have the option of encrypting that connection.
A2. No, pairing/bonding is not required for BLE communication but it is preferred in order to have extra features and extra security on that connection.
A3. No, having no bonding does not affect the stability of your connection/communication. There are a few downsides which include less security on the connection and also potential inability to find the device if privacy is implemented. More details are provided in the link below.
A4. The app is the initiator of the pairing dialog. Specifically, the central device (the one that initiates the connection) is the one that is responsible for initiating pairing. When this central device requests to pair to the remote device, the pairing dialog is shown.
A5. I believe this is dependent on the OS type (Android/iOS) and the version number of that OS, but generally speaking the pairing dialog should not pop up because as the name suggests, it should just work. Pairing dialog pops up when MITM protection is requested.
You can find more details about pairing/bonding and general BLE communication is the answer below:-
Should one create a bond with a Bluetooth LE device
I would also recommend trying the nRF Connect app on both iOS and Android to see the difference between connection and bonding and to verify that you can have normal connections without pairing.
Based on what we got working and based on the answers to this question.
A1: Yes, it's possible if no MITM is set and the Security scheme is set to Just Works, which means no security at all.
A2: Bonding is not required for BLE communication. If the BLE device can't store the Bond information, it may lead to some issues as we got in our case. If the BLE device is able to store and use Bond information then it's recommended to Bond.
A3: The Connection will not be closed. The only downside we got is that now it takes a little more time to reconnect.
A4: The app is initiating the connection, but the dialog is shown only if the BLE device requests some type of security, it can be MITM, encryption, pin. Short answer, the pairing dialog can be avoided by changing the settings on the BLE device.
A5: When having the device with Just Works security protocol, with no bonding and no MITM protection the pairing dialog should not be presented. We got no pairing dialog experience on both iOS and Android.
To add to Youssif's answer:
A3: one difference is that connection setup will be faster since bonding allows the GATT db cache to be used. Otherwise service rediscovery must be done on every connection (if the service changed characteristic is present).
A4: on Android you can call createBond to start pairing, but on iOS there is no API for the security, so either you need to interact with a characteristic that sends an error that pairing is needed, or the remote device can send a Security Request to initiate pairing.
A5: iOS shows a dialog "accept / abort" for just works, Android doesn't.

Can an Android or IOS app make a new bluetooth connection with no user prompts?

I'm working on an app that will talk to certain pieces of hardware via bluetooth.
The app will know the bluetooth password for each hardware device, and know which one you are currently near.
So, even if the phone has never made a connection to a specific device before, it is possible to have my app establish a bluetooth session without prompting the user?
So the user could just press the "connect" button to establish the bluetooth connection.

Android BLE peripheral with pin pairing

I am developing an Android app which behaves as Bluetooth peripheral role with a service.
When I start advertising, other Android devices searching for devices offering this service, can see my device (and can pair to it without pin) - ok.
But how to enable PIN pairing?
You can force the device has to be paired, when using specific characteristics by protecting them with PERMISSION_READ_ENCRYPTED_MITM or PERMISSION_WRITE_ENCRYPTED_MITM.
The client/central side can force pairing by calling BluetoothDevice.creteBond().
The pairing method itself is determinated by the bluetooth protocol (see this thread)
You dont actually require pairing to be done to transmit/receive data via ble, take a look into this tutorial

Can I notify when any bluetooth of paired device is enabled?

Hi I am working with embedded bluetooth device connection with my android application.
My application is installed in Android phone and phone has some paired bluetooth devices, Now I want that if any paired bluetooth device is enabled(starts/turns on) the application should receive notification.
of-course bluetooth will be enabled in phone and bluetooth devices will be within range.
please let me know How this is possible ?
Thanks!
How about using http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_CONNECTION_STATE_CHANGED
To check all changed states and then comparing what the new state is:
STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED etc.
There is nothing automatic that can detect this, you will have to make both your App and the paired device do some work to detect this. TYhere could be 2 options :
Your app could do some periodic device discovery (low frequency - else it will kill the battery) to search for the paired devices in vicinity.
The paired devices on getting enabled / starting on should put itself to be discoverable.
A better way is for the apired device to autimaically initiate a connection once it comes on to the device it was paired with, and typically on most phones by default if Bluetooth is turned on its also scanning for incoming connection , so your app can be ready to accept incoming connections.

Is it possible to send a message from one android mobile to another android mobile using bluetooth or wifi with out pairing?

Presently I am doing my work in the android field. I am trying to develop an application to send a message from my bluetooth/wi-fi enabled mobile to other bluetooth/wi-fi enabled mobiles without pairing.
Is it possible to send message to another mobile in my blueooth or wi-fi range without pairing? If it possible how can I send the message to another mobile with out pairing?
If your talking about SMS this does not apply.
For Wifi have a look at this project http://code.google.com/p/remotedroid/.
For Bluetooth this thread explains how to archive what your looking for.
http://developer.android.com/guide/topics/wireless/bluetooth.html
To send data over to Bluetooth device all you need is the Mac address of that device.
Read the Bluetooth tutorial, its very helpful.
Shortly and sweetly, No.. You cant send messages to other mobiles without some kind of authentication.
For sending Message (SMS,MMS), I don't think so, Without pairing how could you know the device Id, to which you want to send a message, And if you don't pair the devices then how they communicated to each other,
EDIT: For bluetooth As per my knowledge it's impossible to send or receive data over RFCOMM sockets without pairing.
And for WiFi , setup parallel server/client threads on each device, and send whatever you want. To discover services on a local network you can optionally use zeroconf.
Look at these links,
Bluetooth pairing without user confirmation
Bluetooth SPP between Android and other device, UUID and PIN questions
How to send and receive data in Android Programming using bluetooth without pairing?

Categories

Resources