【发布时间】:2019-03-05 12:40:22
【问题描述】:
我想将 Android 设备作为 USB 设备连接到作为主机设备的 STM32 板。
我的 Android 应用程序代码如下:
Android 清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.usb_connection">
<uses-feature android:name="android.hardware.usb.accessory" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
所以当我尝试获取连接的 USB 设备详细信息时,USB 设备列表始终为空:
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
Map<String,UsbDevice> deviceList = manager.getDeviceList();
再次,我也尝试获取附件列表,USB附件列表也是空的。
UsbAccessory[] accessoryList = manager.getAccessoryList();
然后尝试 ADB 命令 连接设备。我在 JAVA 中创建了一个桌面应用程序来运行 ADB 命令并且它工作正常。但是当我尝试从我的 Android 应用程序运行 ADB 命令时,它给出了 java.io.IOException: Error running exec()。命令:[ ADB, pull , ...] 工作目录:null 环境:null.
STM32 固件是用 C 语言编写的。
请帮帮我,我卡了很长时间。
【问题讨论】: