我想创建一个控制连接到PIC18F4550的LED的应用程序。我将发送一个数组但是在发送任何数据之前我想要检测我的USB设备。为了检测我发现了一个简单的例子但是它不工作并且无法找到我做错的地方。
任何人都可以帮助我吗?
最好的问候。
这是我的mainActivity:
import java.util.HashMap;
import java.util.Iterator;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
Toast.makeText(this,"Value of device :" +device.getDeviceName(), Toast.LENGTH_LONG).show();
}
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.usbsenderandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="12" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.usbsenderandroid.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>
</manifest>
device_filter:
<resources>
<usb-device vendor-id="1240" product-id="0063" />
</resources>
这是我连接我的照片时的详细信息
HID \ VID_04D8&安培; PID_003F&安培; REV_0002
HID \ VID_04D8&安培; PID_003F
HID_DEVICE_UP:FF00_U:0001
HID_DEVICE
答案 0 :(得分:1)
我感觉有点伤感来回答我的问题,但我想通了的家伙。问题不在于代码。我在pic的表单页面中找到了:“Android附件必须是USB主机.18F USB PIC是设备,而不是主机”。以下是 description
的链接