1

我有这样的要求,我必须在计算机系统上传输文件,让我们考虑 windows PC。

我想要做的是我有一个带有特定细节的屏幕,我将这些值写入一个文本文件中,现在如果用户单击按钮,则必须使用 USB 将该文件复制到特定位置的计算机。

我试图搜索这个但没有得到任何有用的东西。我也参考了下面的链接

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

在Android中是否有可能,我如何与Windows系统通信?

问候

更新 :

我可以将文件复制到计算机使用adb

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

但我可以从 android 应用程序做同样的事情吗?

4

2 回答 2

0

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.

于 2013-09-04T14:22:17.283 回答
0

我认为您的问题不是很具体,无法回答。但是要解释一下,请考虑以下几点:

  • 您必须将您的 android 设备设置为 USB 主机模式,以便枚举连接的 USB 设备
  • 与您的接收设备建立连接。可能这将是具有已知端点配置的存储或驱动器
  • 建立后,使用bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout),您提供的链接中记录的类似功能。请记住选择正确的端点(指向您的存储/驱动器的方向)

这只是一个让你开始的草图。很明显,还有很多事情要做。

于 2013-09-04T14:00:02.447 回答