8

I have an 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 can this be done?

Chenmunka
  • 685
  • 4
  • 21
  • 25
Vitaliy
  • 166
  • 1
  • 1
  • 8
  • I don't think you can do that. Think again. wouldn't that be a huge security lack? If a an application uses USB without asking, you can do almost everything. That's not the idea. The android device itself can allow it in the settings but not from your application. – greenhoorn Jul 09 '15 at 11:11
  • Maybe there is a way to do this with the help of **root** and install the application as a **system**? – Vitaliy Jul 09 '15 at 11:19
  • For the device is supposed to use **USB Host**, and not to connect to a computer. – Vitaliy Jul 09 '15 at 11:25

2 Answers2

4

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • and added to my device. When you connect USB the system dialog appears for permission, but I need to have permission to receive automatic call without dialog. – Vitaliy Jul 09 '15 at 11:36
  • 1
    When you connect USB the first time (with already installed app), system call permission dialog. Then another time at start app usb will get permission automatically. If you are using root, watch http://stackoverflow.com/questions/13726583/bypass-android-usb-host-permission-confirmation-dialog – Dmitriy Chernov Jul 09 '15 at 11:43
  • A device **without a screen**, but with a predetermined application. When you connect USB device, I will not be able to press the button "OK" and set the default selection. It is necessary to obtain a permit without having to call for dialogue, even the first time. – Vitaliy Jul 09 '15 at 11:52
  • Did everything as in the example, added by analogy missing classes, but my version of Android (4.4.2), I did not get the result. – Vitaliy Jul 13 '15 at 14:15
  • 2
    Can anyone please explain the components of this answer ? – Jaydev Oct 20 '16 at 15:53
4

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.

Community
  • 1
  • 1
Vitaliy
  • 166
  • 1
  • 1
  • 8