Send file to computer system using USB

最后都变了- 提交于 2020-01-11 07:12:53

问题


I have such requirement in which i have to transfer file on computer system, lets consider windows PC.

What i want to do is i have one screen with specific details,i am writing that values in one text file, now if user clicks on button then that file must be copied to computer at specific location using USB.

I have tried to search about this but didn't get anything useful.I've also refer below link

http://developer.android.com/guide/topics/connectivity/usb/host.html

Is it possible in Android, how do i communicate with windows system ?

Regards

UPDATE :

I am able sopy files to Computer using adb

./adb -s emulator-5554 pull /sdcard/juned.jpg /root/juned/android_usb/

but can i do same thing from android application ?


回答1:


I think your question is not very specific to be answered. But to explain a bit consider the following:

  • you have to turn your android device in USB host mode so that it enumerates connected USB devices
  • establish a connection to your receiving device. Probably this is going to be a storage or drive with a known configuration of endpoints
  • when established, use a function like bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout), which is documented as well in the link you provided. Keep in mind to choose the correct endpoint (direction TO your storage / drive)

This is just a sketch to get you started. It's clear that there is a lot more to do..




回答2:


USB is probably not very suitable for what you want to do.

USB is asymmetrical, that is, a USB connection has a host at one end and a peripheral device at the other end. (For example, when you plug a USB stick into a PC, the PC is the host and the stick is the peripheral.) The host initiates and controls data transfers.

An Android phone generally acts as a peripheral device. As of Android 3.1, the phone can also act as a USB host, though not all phones support this.

In order to accomplish what you have in mind, the PC would need to run a piece of software that changes it from host mode to peripheral mode, and exposes some kind of storage that the Android device could then write to.

Maybe Bluetooth is a better option for you. You could just initiate a file transfer over Bluetooth as soon as the file changes. Inexpensive USB Bluetooth dongles are available for PCs without Bluetooth support. You might still need some software on your PC if you want to automatically accept the file transfer request on the PC.



来源:https://stackoverflow.com/questions/18615532/send-file-to-computer-system-using-usb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!