Android Things intent for boot
Asked Answered
C

6

9

When I reboot after deploying an application to Android Things the application doesn't start.

Is there a specific intent to start an application on boot?

Complainant answered 13/12, 2016 at 17:39 Comment(0)
G
17

If your Android Things device has multiple applications installed that all have this intent filter in the manifest:

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.HOME"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

( < DP8 used to need IOT_LAUNCHER that has been deprecated)

Then your application will not start by default, instead the Intent Chooser dialog will be shown and the system will wait for user input to select which app to run. (This happens wether or not you have an actual display plugged in. If you don't have a display it might appear as tho the device is just hanging.)

I wrote a script here: https://gist.github.com/blundell/7c0c3bb17898b28fe8122b0dc230af50 that will uninstall all applications that have the above Intent Filter so that you can start again and only have 1 application installed - therefore this application will start on boot.

script to uninstall example


With the latest version of AndroidThings the IntentChooser will not be shown anymore, however the problem can persist as one of the apps installed is selected to open and the others do not.

Gilgilba answered 8/1, 2017 at 21:54 Comment(3)
I found that a process called IoTLauncher decided to start the first activity with launcher intent: 01-01 00:00:59.516 639-639/com.android.iotlauncher D/IoTLauncher: 2 activities found with launcher intent 01-01 00:00:59.516 639-639/com.android.iotlauncher W/IoTLauncher: Multiple applications with launcher intent found. Launching first found 01-01 00:00:59.624 639-639/com.android.iotlauncher I/IoTLauncher: Software Version 7.0Castara
Is there a way to restore the removed App Chooser functionality - it's actually pretty useful when developing, and in the absence of any kind of home screen.Anaphrodisiac
It'd be quite easy to code up yourself (no you cannot restore it), you could look at the source code for a Launcher app and use the Package Manager to find apps, then create a dialog yourself. Might be fun to do, might be a big waste of time :-)Gilgilba
F
6

Add to AndroidManifest.xml

Developer Preview 0.8 and greater (New Style)

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.HOME"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Before Developer Preview 0.8 (Old Style)

<intent-filter>
   <action android:name="android.intent.action.MAIN"/>
   <category android:name="android.intent.category.IOT_LAUNCHER"/>
   <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

See Android Things Release Candidate 16 April 2018

Fruit answered 16/5, 2018 at 16:8 Comment(1)
First I assume that something like Blundell in the answer above explained and try to delete all apps with this filters, but that didn't help. Changing intent filter as you wrote, app successfully butted after restart device. I'm tring this on AndroidThings 0.8, and in meantime, I updated to 1.0.0. So thanks man!Idun
C
3

The following intent-filter needs to be added to AndroidManifest.xml

<intent-filter>
   <action android:name="android.intent.action.MAIN"/>
   <category android:name="android.intent.category.IOT_LAUNCHER"/>
   <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Complainant answered 13/12, 2016 at 17:41 Comment(0)
R
3

Have you tried their demo app? Try out this first before writing your own app. This should work as expected. Later change as you want.

Just don't remove this part from the AndroidManifest.xml of your code.

<!-- Launch activity automatically on boot -->
<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.IOT_LAUNCHER"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Racine answered 14/12, 2016 at 5:27 Comment(0)
H
0

To give Android Things support in app, We need to define main entry point for the system to automatically launch on boot.

While adding an intent filter for an activity must contain an intent filter that includes both CATEGORY_DEFAULT and IOT_LAUNCHER.

<application
android:label="@string/app_name">
<activity android:name=".HomeActivity">
    <!-- Launch activity as default from Android Studio -->
    <!-- For ease of development, this same activity should include a CATEGORY_LAUNCHER intent filter so Android Studio can launch it as the default activity when deploying or debugging. -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

    <!-- Add below intent filter which enable android things support for app -->
    <!-- Launch activity automatically on boot -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.IOT_LAUNCHER"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

Check Home activity support for Android Things in android app.

Hacking answered 18/12, 2016 at 16:41 Comment(0)
I
0

Answer from user fishjd, help me. If that didn't work, try deleting app using adb, and reinstalling it

adb uninstall <packet>
Idun answered 29/5, 2018 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.