Bluetooth connections servered by the OS get the power back to SweetBlue



  • Hey,

    Hopefully I can get you a good explanation about my problem. I implemented a native Android scan method from the BluetoothLeScanner, because SweetBlue don't provide a scan method with a PendingIntent. But this scan method is really helpful if you want a long running background scan for your devices and the battery use is very low.

    I ask for this feature in an other post and the answer was there is no problem to do it on my self and good to know, in SweetBlue you can have access on the native Android BLE classes via the getNative() methods.

    So I implemented the new feature and it works but there is a litte problem... When Android decide to kill my app and the background service restarts and reconnect to my device, in some cases it can happen what the OS gets the control about the bluetooth connections. And sometimes SweetBlue get stuck in some states, because the states are inconsistent between SweetBlue and the OS. I also have to restart my app twice to do a disconnect via SweetBlue.

    I hope you get what I mean, is there a chance to get the power back to SweetBlue or good workaround for this ? We really need this scan method, because our main use case is to guarantee an energy efficient and automatic background reconnect to our devices. So that the user do not has to open the app, the best case is that our device run automatically and the user can enjoy the experience. We test a lot of other methods but this is the best one.

    Bjoern



  • Bjoern,

    Are you using SweetBlue to connect in this case, or the native android methods?



  • @ryanbis said in Bluetooth connections servered by the OS get the power back to SweetBlue:

    Bjoern,

    Are you using SweetBlue to connect in this case, or the native android methods?

    The scan method is native but the connect call is from SweetBlue. I think the problem is that Android auto connect to bonded devices.



  • Are you enabling the autoConnect parameter?
    Also, from what I've seen, Android OS does not reconnect to bonded devices, except for A2DP ones…
    However, if that is happening, maybe you could disconnect/unbond when you notice that the device is stuck or when your service gets killed?

    Hope



  • @alejandrohcruz said in Bluetooth connections servered by the OS get the power back to SweetBlue:

    Are you enabling the autoConnect parameter?
    Also, from what I've seen, Android OS does not reconnect to bonded devices, except for A2DP ones…
    However, if that is happening, maybe you could disconnect/unbond when you notice that the device is stuck or when your service gets killed?

    Hope

    Hey, the autoConnect parameter is not enabled. Yes I can do disconnect/unbond the device, the problem is that the user has to open the app, because we don't get any response in the background when the Android OS controls the connection and kills our app. Currently we have a little workaround in our device that kicks the smartphone after 2 seconds in a set up state, because we found out when Android OS tries to reconnect, it get stuck in this state. So we can handle it from our device and get the control back.

    Edit:

    Is there a chance to disconnect to a device when the Android OS has the control of the connection ? Like to use the native Android LE methods ? Because if you use the SweetBlue disconnect or shutdown methods the connection is still there..