在AndroidManifest.xml中添加权限,还要编写一个resource文件,具体参考http://developer.android.com/guide/topics/usb/host.html

解决方案 »

  1.   

    请问LZ用的是什么设备测试的啊??我现在也在做这个但是一直拿不到设备啊?求DX教导啊
      

  2.   

    在设备的权限目录中增加文件android.hardware.usb.host.xml,这样就可以获得设备列表了
    内容如下:
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Copyright (C) 2011 The Android Open Source Project     Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at          http://www.apache.org/licenses/LICENSE-2.0     Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
    --><!-- This is the standard feature indicating that the device can communicate
        with USB devices as the USB host. -->
    <permissions>
        <feature name="android.hardware.usb.host" />
    </permissions>
      

  3.   

    我的机器是在/system/etc/permissions下
      

  4.   

    我们自己定制的机器,android4.0.3
    将android.hardware.usb.host.xml文件push到/system/etc/permissions目录下
    然后关机,重新启动ok
      

  5.   

    好像连接建立之前如果是列举的方式获得设备要先申请
    mUsbManager.requestPermission(device, mPermissionIntent);
      

  6.   

    如果在AndroidManifest.xml中增加了红色部分,那么指定类型的设备就自动获得权限了
    否则,在操作之前需要requestPermission获得权限
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="lgx.MyTest"
        android:versionCode="1"
        android:versionName="1.0" >    <uses-sdk android:minSdkVersion="12" />
        <uses-feature android:name="android.hardware.usb.host" android:required="true"/><!-- android:required="true" -->
        
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:name=".MyTest"
                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>
      

  7.   

    mManager.openDevice(device);这个打开设备出错,权限不足楼主怎么解决的啊?那个XML我平板里有啊
      

  8.   

    兄弟还没有搞定啊?就是那么xml文件,只要放到那里就可以了,你的设备具体为什么不行,这个就不知道了
      

  9.   

    急问:楼主定制的机器是手机吗,可以定制手机吗?
    现在有哪款android手机也支持啊
    请回复啊
      

  10.   

    不是手机,所有3.1版本以上的,愿意开放usb接口支持的
    否则需要自己将android.hardware.usb.host这个feature加进去
      

  11.   

    ((UsbManager)getSystemService(Context.USB_SERVICE)).requestPermission(dev, pi);
    上面是关键地方,余下的你自己研究吧