Saturday, February 23, 2019

Working on A2DP Connect2

I finally got around to dusting off the aging A2DP Connect2 widget and getting it updated to work on newer devices better.  I have not yet pushed an update to the Play Store but I am putting signed APKs as I progress here.  I also have the Github page for it here.  I have it compiled for API 19 through the current API 28 (Pie).  I cannot test it in emulators though so I have only tested on Android 7 and Android 8 right now.

The most requested issue, which is posted on the issues list, is to have an indication of the connection state.  I have that somewhat working.  I say somewhat since there is not an interface to get this.  In Android you are supposed to use a background process to listen for Bluetooth connection changes.  These are called Broadcast receivers.  You register your receiver with filters to call back to your service when the connection changes.  In the response, it will tell you details such as profiles that connected and of course the current connection state.  This is how A2DP Volume does it.  There is another back door approach that involves using reflection to access methods that are not exposed.  To do that you must bind to a service that accesses an IADL.  A2DP Volume and A2DP Connect2 use this to make the connect/disconnect happen.  It's tricky and undocumented, and risky as they can change Android and break this with no warning. This happened back when Jelly Bean came out and the Bluetooth stack was replaced.  I have made several attempts at using this method to get connection state but there are incompatibilities between widgets and binding services that I have not yet been successful. 

Update: After hours of trying and failing, it finally seems to work.  Opt in to the beta testers to get the test apk: https://play.google.com/apps/testing/a2dp.connect2Let me know your feedback.

Update 3/9/2019: In order to make the icon change based on connection state, I needed to have a foreground service running which means having a notification icon active.  I thought that was too much for a simple widget.  So, I added a simple call from A2DP Volume (which already has the service running) to run an update service in A2DP Connect2 and update the icon when the state of the Bluetooth connection changes.  This will be in version 2.12.12.5 of A2DP Volume. 

No comments:

Post a Comment