Mintoris Forum

Author Topic: Make your app autorun when USB is Plugged in.  (Read 13234 times)

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Make your app autorun when USB is Plugged in.
« on: Apr 11, 2014, 05:59 PM »
You can make your stand alone apps auto-run when you plug in a USB device. You just need to make a small change to your AndroidManifest.xml and save the attached device_filter.xml to your res->xml directory. The device_filter.xml file defines which devices will trigger the auto-run. If you just want a particular device to run your app, edit the device_filter.xml and remove the devices you don't want.

-Chuck

Here are the changes to the manifest.

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

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.CAMERA" />

    <uses-feature
        android:name="android.hardware.location"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.gps"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.bluetooth"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />
   <uses-feature android:name="android.hardware.usb.host"
        android:required="false" />
   
    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".AutoRun"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
           <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            </intent-filter>
            <meta-data
                android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                android:resource="@xml/device_filter" />
            </activity>
   </application>

</manifest>
« Last Edit: Apr 11, 2014, 06:01 PM by Chuck »

Teet3

  • Newbie
  • *
  • Posts: 1
Re: Make your app autorun when USB is Plugged in.
« Reply #1 on: May 06, 2015, 08:24 AM »
Hello,

I have an android device with a broken Screen Digitalizer.

I would like to use this device for playing promotional clips from USB and I would need the clips to start automatically from USB.

Do I understand correctly that I can use the above solution for starting the videos from USB?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Make your app autorun when USB is Plugged in.
« Reply #2 on: May 06, 2015, 05:05 PM »
Hello,

I have an android device with a broken Screen Digitalizer.

I would like to use this device for playing promotional clips from USB and I would need the clips to start automatically from USB.

Do I understand correctly that I can use the above solution for starting the videos from USB?

The above code might work for you, although Android likes to put up a message box to confirm you wish to use your app to service the USB device that just got plugged in. At least the first time.

If the touch control on your device is broken, then there isn't much you can do. If you have the development tools installed on a pc, you can plug in your device via USB and start and stop apps using the debug connection (ADB).

-Chuck
« Last Edit: May 06, 2015, 05:19 PM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Make your app autorun when USB is Plugged in.
« Reply #3 on: Oct 01, 2015, 12:17 AM »
In the next release I think I am just going to make this a checkbox on the Export Apk Project screen. I just overlooked it.

sanRak

  • Jr. Member
  • **
  • Posts: 6
Re: Make your app autorun when USB is Plugged in.
« Reply #4 on: Sep 25, 2019, 12:34 PM »
АНД
Зиновьевич

Evelynwed

  • Full Member
  • ***
  • Posts: 26
Make your app autorun when USB is Plugged in
« Reply #5 on: Oct 19, 2019, 06:52 AM »
It only reserve, no more