Interacting with device that's already connected to the OS

  • Hi, I'm trying to retrieve and communicate with a BleDevice that was already connected to Android before our app is opened.

    By doing so, the device's advertised services are not specified by the BleManager and the device is in a state of [DISCOVERED, BLE_DISCONNECTED, BONDED, DISCONNECTED]

    1. Why is the device shown as DISCONNECTED if the OS settings list it under the “Currently connected” Bluetooth devices?
    2. Do I need to perform another scan or force the services to be discovered? Or can the available services be accessed trough another method?
    3. How can our app be closed without the BleManager disconnected the devices? So what was already connected stays like that, and what we connected with our app does so too.


  • Are you sure it's really connected? As far as I know, you don't directly connect to devices via the settings menu. You CAN bond, which is why SweetBlue is showing you that the device is BONDED.

  • Interesting that you mention that, I assumed that's how one could connect any kind of device since it works for speakers and input peripherals. But it only bonds the custom device in question without connecting.

    I performed a connection using the nRF app and then checked the state of the BleDevice on our app, which is still shown as [DISCOVERED, BLE_DISCONNECTED, BONDED, DISCONNECTED].

    1. Is it possible to access devices connected like that?
    2. How can our app be closed without the BleManager disconnected the devices?

  • I don't think it's possible to intercept an active connection established outside of your app. That'd be a pretty huge security hole.

    I don't understand what you're asking with the second question there. Could you perhaps rephrase it?

    1. I thought it would be a security issue too, thanks for confirming the hypothesis!
    2. I mean: if we connect a BLE device with our app, will it always get disconnected when our app/process is killed?

  • Ok, yes, all devices will get disconnected when your app closes. I'm pretty sure this is an OS thing. Even though SweetBlue disconnects devices on exiting, if the app crashes, all connections are still closed.

  • Got it, thanks! Will look to alternative solutions like keeping a service in the background. Our goal is to provide push notification capabilities to the custom BLE device.

  • Hi, I'm jumping back into this thread with more information and a couple of questions:

    1. The Nordic's nRF Connect app can detect when I connect the BLE peripheral on my own app and directly interact with it. Which is pretty cool.

    2. Also, when you open up their application and you click 'connect' on a bonded device that is already connected (using my own app), their app connects the services and is able to interact with the peripheral device.

    Q1: How could I achieve the behavior described by point #2? Either manually (user interaction required) or automatically? i.e. when I open up my app, it should detect bonded devices that are connected and enable them to be used right away by the user.

  • @AlejandroHCruz I think the reason why nRF Connect can hook into an open connection is that it performs a scan without filters, but I have also wondered how they are able to do that.

  • @caeduk interesting, I didn't know that you can do that if you scan without filters. We can probably look into their source code and find more hints i.e. see under which conditions they trigger that notification to ask the user if they want to debug the connection