1

我正在使用 Android 2.3.4 在三星 Galaxy S2 中测试我的应用程序

我正在关注

http://developer.android.com/guide/topics/usb/accessory.html

指示。

每当我尝试运行它时,usbManager.getAcccessoryList(); 给空。

甚至我也尝试过将 OTG 电缆和 pendrive 连接到它。

我的清单。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-feature android:name="android.hardware.usb.accessory" />

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <uses-library android:name="com.android.future.usb.accessory" />

        <activity
            android:name=".SplashScreen"
            android:clearTaskOnLaunch="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Advanced"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".Edit"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".Add"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="Main"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                android:resource="@xml/accessory_filter" />
        </activity>
    </application>

</manifest>
4

2 回答 2

2

我有同样的问题,但我的平板电脑有 ICS。如果尝试我所做的,可能会奏效。我一直在寻找这个,但找不到它,但感谢所有花了一些时间回答我们问题的人,以及网络上的 wiki 资源,我想通了。

某些 android 版本中缺少一些文件,例如 AINOL NOVO 7 PALADIN。我认为这适用于任何具有相同问题的 ICS 平板电脑。我知道 Galaxy Tab 也有同样的问题,但由于我没有,我无法确认这一点。如果你这样做,让我知道它是否适合你。

因此,让我们将文件推入并看看它是如何进行的。

将一些丢失的文件复制到系统驱动器中:

$ adb remount

$ adb push AINOL_FIX/system/etc/permissions/android.hardware.usb.host.xml /system/etc/permissions

$ adb push AINOL_FIX/system/etc/permissions/android.hardware.usb.accessory.xml /system/etc/permissions

注意:如果出现错误显示Out of Memory,这是正确的,您必须从系统驱动器中删除一些文件。我推荐一些来自系统/应用程序的动态壁纸。

我知道要编写系统驱动器,您应该具有 root 访问权限,我在执行此操作时已经拥有它,所以如果它不起作用,请 root 它。

您可以从 android 源代码构建或从 USB-HOST API 实际工作的平板电脑获取文件。我从 linaro 为 pandaboard 构建的 ICS 中得到了它们。

现在,您应该尝试查找那些文件,但对于 Gingerbread ,如果它还没有,您还需要将其推 future.usb.accesory.jar入。system/framework

$ adb push AINOL_FIX/system/framework/com.android.future.usb.accessory.jar /system/framework
于 2012-05-26T08:31:14.473 回答
0

来自http://developer.android.com/guide/topics/usb/accessory.html的引用:“如果您正在使用附加库,请将应用程序的最低 SDK 设置为 API 级别 10,如果您正在使用,请将 API 级别设置为 12 android.hardware.usb 包。” 您正在使用 android.hardware.usb 包。因此,您必须将版本设置为 12。

发现错误:-)

并且不要忘记将 SDK 版本真正更改为 12,而不仅仅是声明它!

根据文档,请改用 com.android.future.usb 包。

于 2012-01-23T20:10:01.013 回答