Send file to computer system using USB

前端 未结 2 1360
生来不讨喜
生来不讨喜 2021-01-15 23:06

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

相关标签:
2条回答
  • 2021-01-15 23:47

    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..

    0 讨论(0)
  • 2021-01-15 23:47

    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.

    0 讨论(0)
提交回复
热议问题