Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 858
Vitaliy Avatar asked Jul 09 '15 10:07

Vitaliy


People also ask

What is host mode and device mode in USB?

When the Android-powered device is in host mode, it acts as the USB host and powers the bus. When the Android-powered device is in USB accessory mode, the connected USB hardware (an Android USB accessory in this case) acts as the host and powers the bus. Figure 1. USB Host and Accessory Modes.

What is OTG host mode?

USB On-The-Go (OTG) is a standardized specification that allows a device to read data from a USB device without requiring a PC. With an OTG cable, the device itself becomes the USB host. You can do a lot over an OTG connection, like connecting a USB flash drive or a video game controller to your phone.


2 Answers

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.

like image 120
Vitaliy Avatar answered Sep 27 '22 17:09

Vitaliy


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

like image 26
Dmitriy Chernov Avatar answered Sep 27 '22 18:09

Dmitriy Chernov