Interacting with device that's already connected to the OS
AlejandroHCruz last edited by AlejandroHCruz
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]
- Why is the device shown as DISCONNECTED if the OS settings list it under the “Currently connected” Bluetooth devices?
- Do I need to perform another scan or force the services to be discovered? Or can the available services be accessed trough another method?
- 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].
- Is it possible to access devices connected like that?
- 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?
- I thought it would be a security issue too, thanks for confirming the hypothesis!
- 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.