Transfer files from android to computer via usb programmatically

I am looking for a solution that uses the Android API to transfer a text file from an Android device to a computer via a USB cable. I found a USB host , but I can’t use this because the computer cannot act as a device for the Android host.

Do you have any suggestions on how I can achieve this?

+6
source share
3 answers

I solved this problem using adb status-window to constantly check the status of the device, and when a new device is connected, the necessary files are transferred to the computer using the adb pull command.

To get a portable solution (for example, to work regardless of the Android platform), I simply copied the adb.exe and AdbWinApi.dll files into my application and used adb there.

+3
source

Had a similar problem when the software installed on the PC had to have access to the file inside the Android phone via USB. After much research, this is what worked for me (not sure if this is the best solution, but it worked). Windows has a Windows Portable Device (WPD) API that can be used to list the contents of a device via USB (and copy files between the client and the device).

There are several implementations in java http://code.google.com/p/jmtp/ (it works well, but does not support the copy function from the device to the PC, although there is some support available for this with the source code) the other is jusbpmp (available in the Google repository) (if someone discovers that a well-documented and supported implementation does share)

but since jmtp did not work for me (copying the original compilation (for a 64-bit OS) failed), I wrote a C # program from scratch to copy files from the device to the PC. here is a good tutorial http://cgeers.com/2011/08/13/wpd-transferring-content/

+2
source

You can write an application that will use http to contact your computer and send (POST) data to a known endpoint.

Keep in mind that the application will only have access to data belonging to the application. You will not be able to access an arbitrary file from the file system.

0
source

All Articles