sábado, 2 de novembro de 2013

Using ANT+ USB Sticks with Endomondo on Android

I needed to use my Garmin ANT+ HR Monitor with Endomondo PRO on Nexus 4 running a Suunto ANT+ USB stick with a externally powered USB OTG adapter (DIY). 

Don't understand why, but Endomondo won't support latest ANT+ API, so USB Sticks won't work, only devices which has the chip embedded as most of the high end Xperia, Galaxy S4 (on 4.3), etc...

The solution? Modify the Endomondo PRO apk so that it starts supporting it. As it's a really simple change, don't understand why it wasn't done before.
Hope these steps help someone else out, as I spend more time looking for a solution than doing the mod itself.


Disclaimer:
This requires some knowledge.   I'm assuming you know your way around in sideloading apps on Android, using command line in Linux or Windows and with a code editor.

Prerequisites:
  • Endomondo PRO (or regular) APK. You can't extract the PRO from your phone as it's a paid app, so get it online or get it straight from Play Store with the Chrome Extension APK Downloader: http://codekiem.com/2012/02/24/apk-downloader/
  • smali / baksmali decompiler : http://code.google.com/p/smali/ (you'll need java installed and properly configured)
  • A code editor in case you're using windows, as Notepad++ (for me in Linux, regular Gedit did fine)
  • I RECOMMEND doing this on linux. Install Ubuntu on a virtual machine using Virtuabox on your Windows and be happy. 
Intructions:

1) Open the .apk in an archiver program like WinRar, 7z, whatever, and extract the classes.dex file.

2) Decompile classes.dex file with the command baksmali classes.dex
It'll create a new folder "out" with a lot of files.

3) Open com/dsi/ant/Antinterface.smali in your code/text editor
Use Ctrl+F and search for ".line 1331"
Look for:

.line 1331 
:cond_1e 
sget-boolean v0, Lcom/dsi/ant/AntInterface;->mAntSupported:Z

4) replace: sget-boolean v0, Lcom/dsi/ant/AntInterface;->mAntSupported:Z
with: const/4 v0, 0x1

5) Recompile using smali out classes.dex

6) Open the apk in the archiver again and delete classes.dex. Copy the new classes.dex into the archive.

7) Copy the apk back to your phone

8) Resign the apk. I used ZipSigner. You can get it from the Google Play Store.

9) Make sure you uninstall the original app, then install from the modified apk.

10) Restart your phone.

11) Make sure the dongle is plugged in before you start the app.

Troubleshooting:

It took me some attempts before Endomondo saw the HR monitor when I scanned for it, so don't give up easy!
I used the ANT+ Demo app and the Heart Rate Graph to make sure the Stick was working before getting Endomondo to recognize it.
When you leave any of them running and connected to the stick and do the device search in Endomondo, you'll get a notification about Endomondo trying to get exclusivity for the ANT+ stick. So it'll help you make sure it's working

Reference:
My guide is heavily based on this guide: http://forum.xda-developers.com/showpost.php?p=32863924&postcount=9

Nenhum comentário:

Postar um comentário