简体   繁体   English

通过USB从Android发送简单命令

[英]Sending simple commands from Android through USB

I am a completely new at programming, and must get this task completed for a demonstration. 我是编程新手,必须完成此任务才能进行演示。 I have a Samsung Captivate that I need to send simple messages to a device over USB. 我有一个Samsung Captivate,我需要通过USB向设备发送简单消息。 I'm not worried about having the droid act as host, not the issue here. 我不担心让droid担任主持人,而不是这里的问题。 I just need to find the proper code to access the USB functions in Android 2.1. 我只需要找到适当的代码即可访问Android 2.1中的USB功能。 I need to send simple on/off commands and audio level changes. 我需要发送简单的开/关命令和音频电平更改。

It would seem to me that this shouldn't be that hard, as the droid will communicate with my laptop and act as a storage device, so I know the two can talk. 在我看来,这应该没那么难,因为droid可以与我的笔记本电脑通信并充当存储设备,所以我知道两者可以通话。 Can anybody help me find these resources? 有人可以帮我找到这些资源吗? I have been looking extensively, to no avail. 我一直在广泛寻找,无济于事。

Thanks! 谢谢!

Bill 法案

The simplest solution would be to use the Android Debug Bridge (ADB) which comes with the Android SDK. 最简单的解决方案是使用Android SDK随附的Android调试桥(ADB) It allows to connect to your Android device via USB (AFAIR USB debugging must be enabled on the device). 它允许通过USB连接到您的Android设备(必须在设备上启用AFAIR USB调试)。

If you want to send your commands from a custom [Java] app on the host you could try to use the ADB feature to forward ports from the host onto the device. 如果要从主机上的自定义[Java]应用程序发送命令,则可以尝试使用ADB功能将端口从主机转发到设备上。 Your app on the device could listen to the port and therefore you would have a simple TCP connection between device and the host over USB. 您设备上的应用可以监听端口,因此您可以通过USB在设备和主机之间建立简单的TCP连接。

As Falmarri suggests, there is no access to USB from the SDK. 正如Falmarri建议的那样,无法从SDK访问USB。 From custom firmware, yes, but not the SDK. 是的,是自定义固件,但不是SDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM