Maker of open-source software and hardware.

A cross-platform approach to accessing Android devices over USB

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.

A while ago I wrote a module for Node.js to access MTP devices, documenting the process in three parts. Now, this works great on Linux and macOS, but due to how Windows handles USB devices, the underlying libmtp library works differently under Windows.

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.


I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.

#100DaysToOffload #day24