Android应用,与插入USB端口的设备通信

时间:2022-06-08 23:36:53

I'm thinking about an Android app (with possibly an accompanying physical device), and I'm trying to figure out whether this is something that's feasible.

我正在考虑一个Android应用程序(可能还有一个附带的物理设备),我正在试图弄清楚这是否可行。

1) Let's say I plug my Android to my PC. Would it be possible for an app installed on the PC to communicate with an app running in the cell phone? I just need a very simplistic data exchange, it can even be one-way (just data pushed from the cell phone to the listening app on the PC, whenever the cell phone wants, I don't need any data sent from PC to phone).

1)假设我将Android插入PC。 PC上安装的应用程序是否可以与手机中运行的应用程序进行通信?我只需要一个非常简单的数据交换,它甚至可以是单向的(只需将数据从手机推送到PC上的监听应用程序,无论何时手机需要,我都不需要从PC发送到手机的任何数据)。

When I plug it in, the phone gives me 4 options (charge, disk drive, HTC sync, tethering), which makes me think this is not doable, but still worth the shot.

当我插入它时,手机给了我4个选项(充电,磁盘驱动器,HTC同步,网络共享),这让我觉得这是不可行的,但仍然值得一试。

2) Would it be possible for an app on the PC to talk to an app on the phone through any other way? (Wi-fi, bluetooth, etc). I'm guessing no on wi-fi since neither party has the other's IP (and I want this to kinda just work, not having to input IPs manually all the time).

2)PC上的应用程序是否可以通过任何其他方式与手机上的应用程序通信? (Wi-Fi,蓝牙等)。我猜wi-fi没有,因为任何一方都没有对方的IP(我希望这只是工作,而不是一直手动输入IP)。

3) If I make a device that's plugged to the little USB port at the bottom of the phone (and let's say this is a magical device that can do anything, I don't quite care about those details as long as it's doable). Can I have an Android app talk to that device?

3)如果我将一个设备插入手机底部的小USB端口(让我们说这是一个可以做任何事情的神奇设备,只要它可行,我就不太关心这些细节)。我可以让Android应用与该设备对话吗?

4) Any other ideas to make the phone talk to a "device" that I make, or to an app in the PC are more than welcome. Going "through the web" could be an option (although there'd have to be a central server that I own as a middle man, I believe). But I'd prefer if the communication was direct between the two devices.

4)让手机与我制作的“设备”或PC上的应用程序通话的任何其他想法都非常受欢迎。 “通过网络”可能是一个选择(虽然必须有一个我作为中间人拥有的*服务器,我相信)。但我更喜欢这两种设备之间的通信是直接的。

4 个解决方案

#1


18  

The world has changed since this question was asked, and the answer is now the Android Open Accessory Development Kit. It won't solve the problem for existing USB devices, but it makes it possible to create new devices that can use an Android device's USB connection.

自问这个问题以来,世界已经发生了变化,答案现在是Android开放附件开发套件。它不能解决现有USB设备的问题,但它可以创建可以使用Android设备的USB连接的新设备。

#2


9  

Communication between Android Device and PC is possible in one more way.

Android设备和PC之间的通信可以通过多种方式实现。

Through ADB connection via USB.

通过USB连接ADB。

  1. Port Forwarding.
  2. 转发端口。
  3. Server Socket JAVA Program.
  4. 服务器套接字JAVA程序。
  5. Client Socket Android App.
  6. 客户端套接字Android应用程序。

Through this app can communicate with the our JAVA Program running on PC.

通过这个应用程序可以与我们在PC上运行的JAVA程序进行通信。

http://www.anothem.net/archives/2010/10/15/android-usb-connection-to-pc/

http://www.anothem.net/archives/2010/10/15/android-usb-connection-to-pc/

#3


4  

Edit: Please note this answer predates the availability of the Android USB host and accessory APIs and support found in many devices released after it was written.

编辑:请注意,这个答案早于Android USB主机和附件API的可用性,以及在编写后发布的许多设备中的支持。

If you turn on usb debugging on the phone and have something derived from the sdk's (open source) adb tool on the pc, they can communicate. The pc will have to initiate communications but within the sessions it can be mostly bidirectional or even mostly from device to pc. See developer.android.com about the adb shell and port forwarding. Root not required.

如果您打开手机上的USB调试并从PC上的sdk(开源)adb工具获得一些东西,他们就可以进行通信。电脑将不得不启动通信,但在会话中它可能主要是双向的,甚至主要是从设备到电脑。有关adb shell和端口转发的信息,请参阅developer.android.com。 Root不是必需的。

People are using bluetooth to talk to arduino embedded controllers.

人们正在使用蓝牙与arduino嵌入式控制器交谈。

With root I have made my phone act as a usb host, but it was a pain as I had to use wifi to get a debug shell since the usb was occupied.

使用root我已经让我的手机充当了USB主机,但是因为usb被占用所以我不得不使用wifi来获得调试shell。

Some phones have a low voltage serial port on an extusb connector or audio lines, but root and a level shifter would be required to use this.

有些手机在extusb连接器或音频线路上有低压串行端口,但需要root和电平转换器才能使用它。

Another idea I had been thinking of, doing a software modem on the headset jack, apparently has been done for both android and iphone by someone in Japan. This should not require root.

我一直想到的另一个想法是,在耳机插孔上做一个软件调制解调器,显然已经由日本某人为android和iphone做过。这不应该要求root。

#4


3  

For communication via usb/wlan take a look at this project: http://code.google.com/p/android-notifier/

有关通过usb / wlan进行的交流,请查看此项目:http://code.google.com/p/android-notifier/

#1


18  

The world has changed since this question was asked, and the answer is now the Android Open Accessory Development Kit. It won't solve the problem for existing USB devices, but it makes it possible to create new devices that can use an Android device's USB connection.

自问这个问题以来,世界已经发生了变化,答案现在是Android开放附件开发套件。它不能解决现有USB设备的问题,但它可以创建可以使用Android设备的USB连接的新设备。

#2


9  

Communication between Android Device and PC is possible in one more way.

Android设备和PC之间的通信可以通过多种方式实现。

Through ADB connection via USB.

通过USB连接ADB。

  1. Port Forwarding.
  2. 转发端口。
  3. Server Socket JAVA Program.
  4. 服务器套接字JAVA程序。
  5. Client Socket Android App.
  6. 客户端套接字Android应用程序。

Through this app can communicate with the our JAVA Program running on PC.

通过这个应用程序可以与我们在PC上运行的JAVA程序进行通信。

http://www.anothem.net/archives/2010/10/15/android-usb-connection-to-pc/

http://www.anothem.net/archives/2010/10/15/android-usb-connection-to-pc/

#3


4  

Edit: Please note this answer predates the availability of the Android USB host and accessory APIs and support found in many devices released after it was written.

编辑:请注意,这个答案早于Android USB主机和附件API的可用性,以及在编写后发布的许多设备中的支持。

If you turn on usb debugging on the phone and have something derived from the sdk's (open source) adb tool on the pc, they can communicate. The pc will have to initiate communications but within the sessions it can be mostly bidirectional or even mostly from device to pc. See developer.android.com about the adb shell and port forwarding. Root not required.

如果您打开手机上的USB调试并从PC上的sdk(开源)adb工具获得一些东西,他们就可以进行通信。电脑将不得不启动通信,但在会话中它可能主要是双向的,甚至主要是从设备到电脑。有关adb shell和端口转发的信息,请参阅developer.android.com。 Root不是必需的。

People are using bluetooth to talk to arduino embedded controllers.

人们正在使用蓝牙与arduino嵌入式控制器交谈。

With root I have made my phone act as a usb host, but it was a pain as I had to use wifi to get a debug shell since the usb was occupied.

使用root我已经让我的手机充当了USB主机,但是因为usb被占用所以我不得不使用wifi来获得调试shell。

Some phones have a low voltage serial port on an extusb connector or audio lines, but root and a level shifter would be required to use this.

有些手机在extusb连接器或音频线路上有低压串行端口,但需要root和电平转换器才能使用它。

Another idea I had been thinking of, doing a software modem on the headset jack, apparently has been done for both android and iphone by someone in Japan. This should not require root.

我一直想到的另一个想法是,在耳机插孔上做一个软件调制解调器,显然已经由日本某人为android和iphone做过。这不应该要求root。

#4


3  

For communication via usb/wlan take a look at this project: http://code.google.com/p/android-notifier/

有关通过usb / wlan进行的交流,请查看此项目:http://code.google.com/p/android-notifier/