Solutions

Android app with ANT+

This summer I’ve made an Android app to connect a Garmin Cadence Sensor to stream a video based on cadence (rpm). My goal is to put the cadence sensor on the crank of my hometrainer and based on the rpm I’ll make the video on my screen (tablet, TV or phone) play faster or slower.

First of all, the time of writing is 30th December 2020. A few days after my Android phone, a Samsung Galaxy S20 5G, has updated to Android 11.

My plan is:

  • Find out if there is a SDK available.
  • Find out if anyone has done this before for code examples.
  • How does ANT+ work.
  • What are things to take care of in the Android SDK.

I started to use a search engine and found out the website thisisant.com, a good place to start and more information is available if you’ll register an account there for free. You can go to the downloads page, https://www.thisisant.com/developer/resources/downloads/, and see some old but still useful information.

However the downloadable SDK which they offer is an old version, 3.5.0. After some digging on the internet I found an Android Archive available on the following github page: https://github.com/starryalley/CSC_BLE_Bridge/tree/master/app/libs.

You can look further into the code of that github page: https://github.com/starryalley/CSC_BLE_Bridge. He did some impressive work there as it’s also based on the work of another Github user I would like to state the importance of sharing knowledge.

I just needed the Ant+ code so I removed the BLE code and permissions too and I’ve added a reference to the videoplayer I’m using ( ExoPlayer to be exact) with an RpmLookup table to pass the right value of speed to the player. And this worked until my phone updated to Android 11.

Then it became interesting, first thing I did was to check the app ANT+Tester which resulted in the expected result: I’ve got ANT+. However my own app said it wasn’t installed. followed by an error: W/AntPluginPcc: BBD30800: RequestAccess failed.

And then I began to think what was different since the last time I’ve used the app. A few things came to mind, I’ve added a DialogFragment and my phone had updated. So I looked into the release notes of Android 11, https://developer.android.com/about/versions/11/privacy . And while reading it, I started to think about how the concept of ANT+ works on Android phones.

There are a few apps you need to have installed in order to work properly. A ANT+ plugins service and ANT+ radio service and when using a separate USB dongle you’ll need the USB communicator service too. But in this case this means you’re using the service of another app for their data.

So I stopped after reading the row about ‘Package visibility’, https://developer.android.com/about/versions/11/privacy/package-visibility. As I’m targeting sdk version 30, I’ll need to know more how I can fix it in my project. They’ve updated their documentation on the website and it can be found here how you can manage to read from the antplus service again, https://developer.android.com/training/basics/intents/package-visibility .

The solution which worked for me was to put a queries tag under the manifest and put the antplus package name in there.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <queries>
        <package android:name="com.dsi.ant.plugins.antplus" />
    </queries>
...

</manifest>

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *