首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么usbManager.getAcccessoryList();总是返回null?

为什么usbManager.getAcccessoryList();总是返回null?
EN

Stack Overflow用户
提问于 2012-01-23 20:08:15
回答 2查看 3.1K关注 0票数 1

我正在三星Galaxy S2上用Android2.3.4测试我的应用程序

我在跟著

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

说明。

当我尝试运行它时,usbManager.getAcccessoryList();提供null。

甚至我也试着把OTG、cabel和pendrive连接在一起。

我的舱单。

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

发布于 2012-05-26 08:31:14

我也有同样的问题,但我的平板电脑有ICS。如果尝试一下我所做的,也许会奏效。我一直在寻找这个,却找不到,但是感谢所有花了几分钟回答我们问题的人,以及网络上的维基资源,我想出了答案。

在一些android版本中有一些丢失的文件,比如AINOL NOVO 7圣骑士。我认为这在任何具有相同问题的ICS平板电脑中都是可行的。我知道Galaxy也有同样的问题,但由于我没有这个问题,所以我无法证实这一点。如果你这么做了,告诉我它是否适合你。

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

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

代码语言:javascript
复制
$ 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

注意:如果一个错误显示在内存中,它是正确的,您必须从系统驱动器中删除一些文件。我推荐一些系统/应用程序的实时壁纸。

我知道,对于编写系统驱动器,您应该有根访问权,当我这样做时,我已经有了它,所以如果它不工作,根目录它。

您可以从android源代码构建或从USB主机API实际工作的平板电脑中获取这些文件。我是从linaro为潘德奥特建立的ICS系统里得到的。

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

代码语言:javascript
复制
$ adb push AINOL_FIX/system/framework/com.android.future.usb.accessory.jar /system/framework
票数 2
EN

Stack Overflow用户

发布于 2012-01-23 20:10:01

http://developer.android.com/guide/topics/usb/accessory.html引用的一句话是:“如果使用外接程序库,则将应用程序的最小SDK设置为10级,如果使用android.hardware.usb包,则设置为12级。”您正在使用android.hardware.usb包。所以,你必须把版本改为12。

发现一个错误:-)

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

根据文档,使用com.android.future.usb包代替。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8977885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档