Thursday, April 28, 2016

Programmatically transfer file from Windows to Android phone

Hello Community,

By now, everyone knows Android has dropped support for USB Mass Storage access to its folder. Which means a Windows computer can no longer programmatically copy a file from Windows to a USB-connected Android device.

I have a Windows application that needs to be able to drop a text file from time to time onto an Android phone. I also have an Android app that monitors a certain folder on the device and processes those text files as they come in. In the past, all I had to do on the Windows side was to map a drive pointing to the Android device and my Windows app would then be able to copy the files to that drive. But that doesn't work anymore with more recent versions of Android.

The phone and the computer may be located in an environment where no wifi is available or where both devices are not on the same wifi network. The computer may also not have bluetooth capabilities. In other words, the only thing I can count on with certainty is the USB connexion between the phone and the computer.

I could use a batch file calling ADB, but since different phones may have different ADB drivers, it means I can't provide a generic way for my Windows App to transfer a file to any Android phone. And I have no control over which phone gets connected to which computer. In addition, I can't use a GUI based application to transfer the files: my Windows application needs to run unattended, without having to wait for user action. The same is true of the Android application.

I know there are a number of WebDav/FTP/Bluetooth applications I can install on the Android device so that it can expose a folder to outside computers, but they all rely on over the air connectivity. I tried to find information on writing my own Android Server application that would "publish" a folder to the PC to which the phone is connected via USB, but I can't find anything of use in the Android SDK documentation; the USB stuff all pertains to IoT, not to the actual link that gets established between a PC and a phone. I think what I need to do is to write an app that turns the device into some kind of Samba server that's accessible through the USB connecion, but I have no idea where to start looking for documentation on doing it.

Does anyone have any pointers on how to accomplish this?

PS: please don't start asking questions like "Why do you need to drop a file onto the phone", or "Why don't you just make sure Wifi or bluetooth is always available?". I already explained those restrictions and they are there for very good reasons. So thanks for staying on topic.


from xda-developers http://ift.tt/1rlpYQF
via IFTTT

No comments:

Post a Comment