A cross-platform approach to accessing Android devices over USB

May 19, 2020

While an Android device can be accessed from Windows over USB, it doesn't mount with a drive letter, like USB mass storage devices (e.g., flash drives) do. Well, earlier Android devices used to, but newer ones only support MTP and/or PTP. This means it's really hard to access them programmatically if you're developing a cross-platform app and not using the Windows APIs.

If you don't want to ask the user to navigate to a file on an Android device on Windows themselves, one option would be to automate the task using PowerShell. I've taken that approach in the Tidepool Uploader, where I use the node-powershell module to find and download a file from an Android device. It mostly works, but in a small number of cases this approach fails.

This makes me wonder if I can get my node-mtp module working under Windows, even if it means installing a USB driver for the Android device so that libusb can access it. First step: Getting libmtp compiled under Windows using MSYS2/MINGW64.

PS: If you know of a better way to do this, get in touch: gerrit at tidepool.org.