Android USB Host. How do I get permission to use USB devices without displaying a dialog?

三世轮回 提交于 2019-12-21 21:28:58

问题


There android device without a screen. When connecting the USB device automatically appears the system dialog to permit the use of USB. It is necessary to obtain a permit without using the device's screen. It is assumed that the device application will be installed in advance, and when the USB device is connected automatically.

How exactly this can be done?


回答1:


I made by analogy in the topic. Classes for the correct version of SDK took away. I create the necessary packages and copied to the specified and missing classes. The application should be copied into the folder system/priv-app and all earned.




回答2:


Add to activity in manifest file

<activity ...>
    ...
    <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>

Create file with params of your usb device in res/xml

<?xml version="1.0" encoding="utf-8"?>

<resources>
    <usb-accessory manufacturer="Google, Inc." model="DemoKit" version="1.0" />
</resources>

Fore more information see https://developer.android.com/guide/topics/connectivity/usb/accessory.html



来源:https://stackoverflow.com/questions/31315355/android-usb-host-how-do-i-get-permission-to-use-usb-devices-without-displaying

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!