11

I am looking for a solution which uses Android API to transfer a text file from an Android powered device to a computer through USB cable. I have found USB host but I cannot use this because the computer can not act as a device for the Android host.

Do you have any suggestions how I can achieve this?

Alex P.
  • 30,437
  • 17
  • 118
  • 169
niculare
  • 3,629
  • 1
  • 25
  • 39
  • 1
    Are you wanting to do this programmatically? Or do you simply need to plug in the device and drag and drop files? – FoxMulder900 Apr 03 '13 at 18:33
  • I want to do it programmatically, as I have mentioned in the question "which uses Android API". – niculare Apr 03 '13 at 18:34
  • 1
    I see, I am not sure if this is possible without an application on the client machine, otherwise it would probably be a large security risk. – FoxMulder900 Apr 03 '13 at 18:36
  • You can not do that without a client application on the PC. – 323go Apr 03 '13 at 18:38
  • 1
    @323go This is also an option, but if I implement an application on the PC, I am not allowed to use adb, since the computer would not have Android SDK installed. Is there any option besides adb? – niculare Apr 03 '13 at 18:40
  • adb packages quite nicely (single exe) and is available in source, so you could certainly build on that. – 323go Apr 03 '13 at 18:42
  • 1
    @323go Then if I use Java for the application on the PC, I would pack `adb.exe` into jar and extract it when the jar is ran for the first time in order to be able to use it? – niculare Apr 03 '13 at 19:20
  • Sure, that would work. If you go native, you can just include adb.exe in the installer. – 323go Apr 03 '13 at 19:28
  • @niculare are u succeeded in that ? ,because i want to do the same :) – Juned Sep 04 '13 at 13:14
  • @juned I have posted the answer. Hope this helps. – niculare Sep 04 '13 at 19:23

3 Answers3

6

I have solved this problem by using adb status-window to continuously check for device status, and when a new device is connected, the required files are transferred to the computer using adb pull command.

In order to achieve a portable solution (i.e. to run independently of Android platform), I just copied the files 'adb.exe' and 'AdbWinApi.dll' into my application and used the adb from there.

niculare
  • 3,629
  • 1
  • 25
  • 39
  • 2
    After copying `adb.exe` and `AdbWinApi.dll` file what should i do ? running this `Runtime.getRuntime().exec("adb -s pull /sdcard/juned.jpg /root/juned/android_usb/");` will be okay, or i need to do anything else ? – Juned Sep 14 '13 at 14:26
2

Had similar problem where a software installed in PC needed to be able to access file inside the android phone through USB. After long research here is what worked for me (not sure if this is the best solution but it worked). Windows has Windows Portable Device(WPD) API which can be used to enumerate contents of a device through USB (and copy files between client and device).

There are few implementations in java http://code.google.com/p/jmtp/ (works well but doesnt support copy function from device to pc though there is some support available to do this with source code) another one is jusbpmp (available in google repository) (if somebody finds a well documented and maintained implementation do share)

but since jmtp didnt work for me (copy function source compilation(for 64bit OS) failed), wrote C# program from scratch to copy files from device to PC. here is a nice tutorial https://github.com/geersch/WPD/blob/master/src/part-3/README.md

Christophe Geers
  • 8,564
  • 3
  • 37
  • 53
dibs
  • 41
  • 7
  • @ChristopheGeers - your answer is old, but thought I'd check to see if anybody has built anything that would take files directly from an android phone to a mass storage device (via/through my Windows 10 PC). Thanks for any help at all! – mountainclimber11 Jun 03 '23 at 15:59
0

You can write an app which will use http to contact your pc and send (POST) data to a known endpoint.

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

mfeingold
  • 7,094
  • 4
  • 37
  • 43