I have a Bluetooth module that I'd like to automatically connect with my Android phone. Here's what I've done so far:
The phone and Bluetooth module are paired.
I have an app which creates a BluetoothServerSocket with listenUsingInescureRfcommWithServiceRecord(<uuid>), and then calls accept() on that socket (this is all done in a service).
This works when the Bluetooth module tries connecting to the phone's Bluetooth MAC address.
This also works when under "Bluetooth settings" on the phone, I check the box next to my device to make the phone visible to all devices.
This does not work when the phone is not discoverable to everyone. When the check box is unchecked, it says under my phone "Only visible to paired devices" - my understanding of this is that the phone should be visible to my Bluetooth module, since they are indeed paired... Does anyone have any advice as to why this wouldn't be the case?
Related
I can discover devices and createbond. It's working fine.
But when the user close the app and open again I'm already in bonded state and I only need open serial socket but I can't find the device!
GetBondedDevice gives all the device connected before and also the active one.
Because of that I can't understand is it realy connected and ready to open serialsocket!
Serial socket is not always active. I'm closing onDestroy or onPause to stop communicate.
To simplfy the question: I want to check if given mac address is paired and ready to open serial socket.
As you mentioned, paired devices and connected devices are two different things as follows:-
Paired devices: these are devices that have exchanged security keys and are therefore 'linked' to your Android device (this makes the reconnection easier). These can be either connected or unconnected.
Connected devices: these are devices that have an active channel with your Android device that can be used to exchange data.
In your case, to get devices that have an active connection to your device, you can use the getConnectedDevices or getConnectionState.
You can find more references here:-
How can I programmatically tell if a Bluetooth device is connected
Android: List connected Bluetooth devices
List connected Bluetooth devices
We are developing an application which needs the BLE Peripheral to be automatically paired with the smartphone when the smartphone is near the BLE Peripheral.
We are using RN4871 Microchip BLE Board,
First time when I pair the device from the settings, then power of the device and power on the device, it doesn't show in the Connected Device list, I mean Android doesn't automatically gets connected. Whereas this behavior is not seen in case of Bluetooth Headset.
What is the difference between a BLE Peripheral and Bluetooth Headset, how can i achieve this behavior
That a device is paired (or more correct, bonded) generally just means that the central and peripheral stores keys used for encryption etc. when they later connect.
FYI Peripherals can be programmed so that they advertise with a specific Bluetooth device address as target.
Back to your question. In Android, an "application" must initiate a connection to a device to make it connected (no matter if it's paired or not). That can either be a normal app you install or the built-in HID application in the Bluetooth stack. That said, the HID application will automatically connect to enabled bonded HID devices. So basically, if no application wants the peripheral connected, it won't stay connected.
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
I am implementing Bluetooth Low Energy's HID over GATT (HOGP) profile on Android Lollipop. My target is to use the phone as a keyboard/mouse, which can just plug and play with the default BLE (HID) drivers in Windows 8.1 laptop. The Android phone is supposed to act as BLE peripheral and the laptop should be in BLE central role.
Currently, I am able to establish a very short connection with the laptop. But just right after I enter the passkeys, and bonded successfully with the laptop, the BLE connection will be lost. Have anyone faced this kind of problems before? Or have any solutions on it?
Also, I failed to add generic access service to the gatt server in Android. I am curious if GAP service is included in Android BLE communication by nature? The reason I want to include this service is for defining the "device name", "appearance", and the "peripheral connection parameter update" characteristics. How I can do so?
Did you get your system fixed, I am seeing something kind of similar, where after bonding, my device will go to paired list, then about 20 sec later, the bluetooth on /off button will automatically switch to off position, wait 10 sec, then back
to on position, and my device is gone..
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.