解决方案 »

  1.   

    那要了解设备相关接口或者别的信息。
    设备都不支持你用的那些api,设备都无法识别,你乱导入库也没用呀。
      

  2.   

    谢谢,那请问如果普通车载usb,应该如何获取相关的usb信息?还有我试过把手机当做附件接在小米盒子上,小米盒子可以读取手机sd卡中的内容,但是手机无法识别小米盒子为accessory,小米盒子应该支持这些接口把,为什么获取不到呢
      

  3.   

    你使用的是accessory mode吧?使用的是add-on类库吧?
      

  4.   


    是的Google APIs 14的
      

  5.   


    是的Google APIs 14的这里有相关的说明和简单操作,你看看先。
    http://www.2cto.com/kf/201211/171678.html
      

  6.   

    http://blog.csdn.net/feiyangxiaomi/article/details/19617179
      

  7.   


    谢谢,这些文章我之前也看过,现在我直接列举附件设备都获取不到
    是报异常还是直接获得对象为空?为空应该是权限的问题,你试试以下方式:
    To enable USB host API support you should add a file named
    android.hardware.usb.host.xmland containing the following lines:<permissions>
     <feature name="android.hardware.usb.host"/>
    </permissions>into folder/system/etc/permissionsin that folder find file namedhandheld_core_hardware.xml or tablet_core_hardware.xml and add<feature name="android.hardware.usb.host">
      

  8.   


    谢谢,这些文章我之前也看过,现在我直接列举附件设备都获取不到
    是报异常还是直接获得对象为空?为空应该是权限的问题,你试试以下方式:
    To enable USB host API support you should add a file named
    android.hardware.usb.host.xmland containing the following lines:<permissions>
     <feature name="android.hardware.usb.host"/>
    </permissions>into folder/system/etc/permissionsin that folder find file namedhandheld_core_hardware.xml or tablet_core_hardware.xml and add<feature name="android.hardware.usb.host">
    host我这边是好的,可以获取u盘信息,就是accessory不行
      

  9.   


    谢谢,这些文章我之前也看过,现在我直接列举附件设备都获取不到
    是报异常还是直接获得对象为空?为空应该是权限的问题,你试试以下方式:
    To enable USB host API support you should add a file named
    android.hardware.usb.host.xmland containing the following lines:<permissions>
     <feature name="android.hardware.usb.host"/>
    </permissions>into folder/system/etc/permissionsin that folder find file namedhandheld_core_hardware.xml or tablet_core_hardware.xml and add<feature name="android.hardware.usb.host">
    host我这边是好的,可以获取u盘信息,就是accessory不行
    方便贴代码看看不?我也是黔驴技穷了。
      

  10.   

    其实我代码很简单的,就是测试一下,你看一下把<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.test"
        android:versionCode="1"
        android:versionName="1.0" >
    <uses-feature android:name="android.hardware.usb.accessory" /> 
        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="17" />

        
    <uses-permission android:name="android.hardware.usb.accessory" />
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            
            <uses-library android:name="com.android.future.usb.accessory" />
     
    <activity android:name="com.example.test.usb.MyUsbAccessary" >
        <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_ACCESSORY_ATTACHED" />
         </intent-filter>
     
         <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
             android:resource="@xml/accessory_filter" />
            
                
            </activity>
           
        </application></manifest>public class MyUsbAccessary extends Activity {
    private static final String ACTION_USB_PERMISSION = "com.UARTLoopback.USB_PERMISSION";
    public static String ManufacturerString = "mManufacturer=FTDI"; 
    public static String ModelString1 = "mModel=FTDIUARTDemo";
    public static String ModelString2 = "mModel=Android Accessory FT312D";
    public static String VersionString = "mVersion=1.0"; @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_myusb); final UsbManager manager = UsbManager.getInstance(MyUsbAccessary.this); new Handler().postDelayed(new Runnable() { @Override
    public void run() {
    UsbAccessory[] accessoryList = manager.getAccessoryList();
    if (accessoryList == null) {
    Toast.makeText(MyUsbAccessary.this, "null", 3000).show();
    } else {
    Toast.makeText(MyUsbAccessary.this, accessoryList[0].getDescription(), 3000).show();
    }
    }, 3000); }}