Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

onDeviceConnected() method not reached in auto connect mode #10

Open
b-a-9-0 opened this issue Mar 4, 2015 · 5 comments
Open

onDeviceConnected() method not reached in auto connect mode #10

b-a-9-0 opened this issue Mar 4, 2015 · 5 comments

Comments

@b-a-9-0
Copy link

b-a-9-0 commented Mar 4, 2015

Hi, I set a BluetoothConnectionListener (setBluetoothConnectionListener(new BluetoothConnectionListener()) in auto connect mode. How do I detect when a device is connected? The BluetoothConnectionListener doesn´t work in this case?

@akexorcist
Copy link
Owner

Ahh. This is my fault to use BluetoothConnectionListener in auto connection mode. I will fix this problem.

Thank you!

@naevtamarkus
Copy link

Hi,

I was just going to report on this and I found this thread... +1!

I would be happy also to provide the fix, but I have two or three options and would like to know which one you prefer:

  • Extend AutoConnectionListener() with three new methods (the three from BluetoothConnectionListener). That's probably the cleanest, but it's not backwards compatible (since it's an interface, and people would need to implement the 5 methods).
  • Create a second "private BluetoothConnectionListener mBluetoothConnectionListenerBackup = null;" and set it up to the previous mBluetoothConnectionListener before overwriting it. This is transparent to the user, but not entirely clean, since one would need to maintain both ConnectionListeners across all methods and I see bugs coming :)
  • Create an additional interface AutoConnectConnectionListener with the three famous methods that the user will have to define on purpose. It's obviously not transparent, but probably the most clean way to do it and backwards compatible. One could also define different behavior for normal Connect and AutoConnect.

Does it sound right? Methods 1 and 3 should be pretty straightforward. I can provide you with a Pull Request if you are interested.

@naevtamarkus
Copy link

BTW, I think onAutoConnectionStarted() is not really useful, since it's predictable and not "delayed" to be a callback method. Anyway, just saying.
Also, if you get rid of onNewConnection() and keep only the three methods from Interface BluetoothConnectionListener passed as parameters to setAutoConnectionListener(), the code would remain much cleaner (onDeviceConnected could replace onNewConnection)
Not backwards compatible, of course.

@b-a-9-0
Copy link
Author

b-a-9-0 commented Mar 19, 2015

I now used the BluetoothStateListener to check the connection state. I also think onNewConnection() is not useful. I would prefer the solution you just described and which is not backward compatible.

@naevtamarkus
Copy link

Mmmm maybe this is not such a great idea. I tried it in my app, and it gets very confusing because Connect and AutoConnect callbacks are different (and one overwrites the other).

I think the only solution that makes sense is actually the second, but with a different concept: there should be a manual callback (BluetoothConnectionListener, defined by the user) and an automatic/transparent callback (also BluetoothConnectionListener, only set/unset when AutoConnect is active/inactive) that would take precedence and call the first after finished.

I hope it makes sense. Will work on a PR soon enough.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants