Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Detect ANT+ capability without installing plugin

Rank

Total Posts: 7

Joined 2013-02-12

PM

Is there a way to detect whether there are chances that the current device supports ANT+, even before installing ANT+ Plugin App?

I think most users don't know what ANT+ is, especially when they own a phone without support for it.
I'd like to remove all menu entries regarding ANT+ (e.g. device pairing) on devices which definitely do not support ANT+. (I suppose that there are not many guys who work with USB adapters for ANT as these days most devices support BLE and when doing sport activities dongles will just break.)

So, can I check this in code? Of course there's not something like
getSystemService(Context.BLUETOOTH_SERVICE

but perhaps a low-level routine in the ANT+ library is doing similar things?

At the moment many users do:
* scan for device
* Message: dependency missing, install ANT+ Plugins Service
* install ANT+ Plugins Service
* scan again
* Message: dependency missing, install ANT+ Radio Service
* install ANT+ Radio Service
* scan again
* Message: Error UNKNOWN.
* Rate app: 1 Star, "my Heart Rate sensor is not detected"

Would you recommend checking whether ANT+ Radio Service is installed?

PackageManager.getPackageInfo("com.dynastream.ant.radio.idontknow", ...) 


When this service is not installed, this would be a strong indicator that there is no ANT chip on the device.

Any comments?      
RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

It is actually kind of complicated. Unfortunately different manufacturers don't always follow our recommended solutions so there isn't one single way to deterministically figure out ANT support without the ANT Radio Service actually performing a query for available adapters.

See https://github.com/ant-wireless/ANT-Android-SDKs/blob/master/ANT_Android_SDK/Tools/Android_ANTSupportChecker_1-2-0.apk?raw=true for some of the different variables to consider. Here are some of the key ones:

* Any certified device with built-in support should have the antradio-library installed in the firmware: you can check for this with
Arrays.asList(packageManager.getSystemSharedLibraryNames()).contains(com.dsi.ant.antradio_library


* Otherwise, if the manufacturer didn't include the library or the user is using an external adapter like a USB stick, you have to query for available ANT services with
packageManager.queryIntentServices(new Intent(com.dsi.ant.intent.request.SERVICE_INFO), PackageManager.GET_META_DATA); 

If the result is not-empty that means the phone has services installed which are proclaiming to provide ANT adapters.

* Finally, the user may not have any services installed but still have the ability to add ANT support by using a USB adapter over OTG. Then you need to query the phone if USB host is supported and let the user know they can go that route.




In the end, if you can install it, or if it is already installed I think the easiest approach is to use the ANT Radio Service to query for adapters or channels and watch for 'adapters not available' result.


I might have missed something there, let me know if you have more questions.      

Signature

Dynastream Developer

Rank

Total Posts: 7

Joined 2013-02-12

PM

This is a very comprehensive answer. Many thanks for going into details and providing a handy solution. I'll try it.

Edit:

Not a big surprise, but It works!
Tried on Emulator (both tests failed) and on Sony XPERIA Z1 Compact (first test succeeded).

/**
 * Detect whether it's worth to use ANT+ services (besides USB OTG Support).
 *
 * @param context the typical context which is necessary for almost any operation
 * @return <tt>true</tt> when ANT has been detected, <tt>false</tt> otherwise
 */
public static boolean isAntPresent(Context context{
    PackageManager packageManager 
context.getPackageManager();

    
// Any certified device with built-in support should have the antradio-library
    // installed in the firmware
    
boolean containsAntRadioLibrary Arrays.asList(packageManager.getSystemSharedLibraryNames())
            .
contains("com.dsi.ant.antradio_library");

    if (
containsAntRadioLibrary{
        Log
.d(TAG"device contains antradio_library");
        return 
true;
    
}

    
// Otherwise, if the manufacturer didn't include the library or the user is using an
    // external adapter like a USB stick, you have to query for available ANT services with
    
List<ResolveInforesolveInfos packageManager.queryIntentServices(
            new 
Intent("com.dsi.ant.intent.request.SERVICE_INFO"), PackageManager.GET_META_DATA);

    if (
resolveInfos != null && resolveInfos.size() > 0{
        Log
.d(TAG"device might have ANT services installed");
        return 
true;
    
}

    Log
.d(TAG"device does NOT support ANT");
    return 
false;
     
Rank

Total Posts: 5

Joined 2018-07-30

PM

ShaneG - 19 April 2016 10:23 AM

* Any certified device with built-in support should have the antradio-library installed in the firmware: you can check for this with
Arrays.asList(packageManager.getSystemSharedLibraryNames()).contains(com.dsi.ant.antradio_library

In the end, if you can install it, or if it is already installed I think the easiest approach is to use the ANT Radio Service to query for adapters or channels and watch for 'adapters not available' result.


I checked your ideas and found that in accordance with first test the antradio_library is not installed on my phone, however the second test - the phone has services.

I suppose this is a reason why my app don't start the search (see this topic). Could I install the antradio_library manually on the phone?
Should I use ANT API instead ANT+ in case of this reason?      
Rank

Total Posts: 1

Joined 2018-01-30

PM

Alternatively you could just call
AntPluginPcc.getInstalledPluginsVersionNumber 
If the returned value is not negative then the device should support Ant+

https://www.thisisant.com/APIassets/Android_ANT_plus_plugins_API/com/dsi/ant/plugins/antplus/pccbase/AntPluginPcc.html#getInstalledPluginsVersionNumber(Context)