Discovering Bluetooth Devices only for devices with a required application - android

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.

Related

Securely connect Bluetooth device to Android

I am developing a device that needs to communicate securely to an Android app via Bluetooth. I need that only a predefined phone to be able to communicate with my device for security reason. And I also need to assure that this is not an intruder device that is trying to communicate falsified data to the app.
Looking at Bluetooth specs, I had the impression the only way to do that is with out of band (OOB) authentication with a pre-provisioning temporary key (TK). This looked very promising but after trying to find how to use OOB on an Android app, it seems like it is not supported.
Is it still possible to use OOB authentification on Android ?
If no, is there another alternative to solve my issue ?
This is doable but it depends on the BLE peripheral that you are developing and the features that it supports. Namely, your device needs to support Whitelisting and bonding. This is how it should work.
Upon first connection to the BLE device, the BLE device should accept the connection regardless.
Once the connection is made, the central device (Android phone) needs to initiate bonding. This doesn't need to be Out of Band (OOB) bonding, and the standard Just Works bonding should do.
Once bonding is succesful, the BLE peripheral should add the Android device's IRK to the list of whitelisted devices.
From this point onwards, the BLE peripheral will activate the whitelist, and therefore only devices in the whitelist will be able to connect to your BLE peripheral, and in your case it will be the Android phone that you used to make the very first connection.
It is not straight-forward and requires an initial secure-less connection with the target phone, but if that is not an issue then this should work.
You can find more information about this in the links below:-
Set and activate whitelist with Android phone
Android BLE server - allow only previously connected device to connect
Whitelisting with resolvable random addresses

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

How to check a Bluetooth remote device has been connected with a different phone in Android?

My android application has to connect to a remote Bluetooth device whose Bluetooth address is known to the app. The application will not be able to connect to the device if it is already connected with a different phone as the remote device can accept connection from a single phone at atime. In such cases, the app has to display an alert of "device is already paired with a different phone". My question is how the app can detect whether the remote device is already connected to a different phone ? I know BluetoothAdapter.startDiscovery() can be used to check whether the device is discoverable. But I am not using this as the app knows the bluetooth address of the device, also I don't want to use it as it is a time consuming process. So is there an alternative method to detect it?

how to connect an embedded device to bluetooth chat application in android?

I have a bluetooth hardware device ( embedded one ) that is acting as a client and connecting with pairing permissions automatically to any device whose bluetooth is ON. But it is not connecting to the BT chat application installed on my android phone. The BT chat application works fine when it connects to my hardware device as a slave. But in case of my hardware device acting as a client and BT chat acting as a listening server, connection fails.
Does the AcceptThread code works only on application level and not on system level?
The hardware device connects my android phone at system level but not to bluetooth chat application.
Is there any solution?
Bluetooth chat app basically supports only classic bluetooth.
Please check the bluetooth profile of your embedded device. Does your embedded device supports classic bluetooth?
I suspect your chat application is using createRfcommSocketToServiceRecord().
Use the createInsecureRfcommSocketToServiceRecord instead. Insecure socket allows the RFCOMM to communicate with a non-authenticated paired device. Embedded devices like the RN42 or KC2114 have a difficult time performing authenticated pairing, because user interaction is required (numeric comparison, yes-no response). The "Just Works" automatic pairing will not produce an authenticated pairing. KC2114 supports both automatic authenticated pairing (with a small hack) and Just Works non-authenticated pairing.

How to build this android app (Bluetooth technology)

I am a little confused on how to build this android app. Here's how it should work. I have a list of paired bluetooth devices. Lets say paired devices are:
1. A bluetooth head set.
2. A mobile phone.
And my app should automatically connect only to my headset when ever it comes in range.
Thats the basic functionality. I have been doing some research on bluetooth technology and its implementation. I came across the bluetooth chat application, when I started using the application I realized that both phones should have the app on it in order to connect and exchange messages. I tried connecting to my headset but it doesnt connect. And also when I removed the bluetooth chat app from one of my device and tried to connect it from a device which had bluetooth chat app, the devices couldnt connect.
If you have already worked on bluetooth this might look very simple. But how can I connect to a bluetooth device from my app when ever its in range even if the other device doesnt have my app.
Thanks.
This will be a 2 sections answer:
-To connect to a Bluetooth Headset, check my answer on here
-To Always connect to that device, you can save device address to memory then create a service with BroadCastReciever that listens for Bluetooth Connectivity. and check which device gets connected and compare it address to the one save in memory once its finds it connected call ibth.connect(device). ibth is inside the above link.

Categories

Resources