Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Android app: HeartRate sensor: cant getDeviceNumber();

Rank

Total Posts: 6

Joined 2013-09-11

PM

Hello,

I am trying to connect to HeartRate sensor to Android phone using ANT (not ANT+) SDK. Due to nature of the project, I cant use ANT+ pluging as they invoking their own searching dialogs etc. However I've managed connect to sensor and get broadcasted HeartBeatCount with just basic ANT functions.

Problem is then I try
private void updateData(DataMessage dataMessage){
.....
if (dataMessage.hasExtendedData())
if(dataMessage.getExtendedData().hasChannelId())
mSerialNumber = dataMessage.getExtendedData().getChannelId().getDeviceNumber();

it crashes inside of ANT library:
=====================================
09-30 15:48:13.702: W/dalvikvm(11838): threadid=11: thread exiting with uncaught exception (group=0x41c032a0)
09-30 15:48:13.707: E/AndroidRuntime(11838): FATAL EXCEPTION: AntChannelCommunicatorAidl Receive thread
09-30 15:48:13.707: E/AndroidRuntime(11838): java.lang.ArrayIndexOutOfBoundsException: length=9; index=9
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.message.MessageUtils.numberFromBytes(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.message.MessageUtils.numberFromByte(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.message.ExtendedData.parseFlaggedExtendedMessage(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.message.ExtendedData.<init>(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.message.fromant.DataMessage.getExtendedData(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.optalert.app.optalertantapp.MainActivity$3.updateData(MainActivity.java:253)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.optalert.app.optalertantapp.MainActivity$3.onReceiveMessage(MainActivity.java:282)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.channel.AntChannel$ChannelEventDispatcher.onReceiveMessage(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.channel.ipc.aidl.AntChannelCommunicatorAidl.onRxAntMessage(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at com.dsi.ant.channel.ipc.aidl.AntChannelCommunicatorAidl$AntIpcEventReceiver.handleMessage(Unknown Source)
09-30 15:48:13.707: E/AndroidRuntime(11838): at android.os.Handler.dispatchMessage(Handler.java:99)
09-30 15:48:13.707: E/AndroidRuntime(11838): at android.os.Looper.loop(Looper.java:137)
09-30 15:48:13.707: E/AndroidRuntime(11838): at android.os.HandlerThread.run(HandlerThread.java:60)
=====================================

Equipment used:
Samsung S3, Nexus 7 both with Android 4.3 and USB Host support
Garmin USB Ant Stick
GARMIN PREMIUM HEART RATE MONITOR HRM

Please advise how to get device number; and I presume it should not crash like this after dataMessage.hasExtendedData()?

Thanks.
     
Avatar
RankRankRankRank

Total Posts: 129

Joined 2010-11-30

PM

The only supported approach to connect to ANT+ devices from an Android application is through the ANT+ API and ANT+ plugins.

Please see the discussion here which will point you to the reference code for implementing your own connection UI.