Create an Android Things project

Things apps use the same structure as those designed for phones and tablets. This similarity means you can modify your existing apps to also run on embedded things or create new apps based on what you already know about building apps for Android.

This lesson describes how to prepare your development environment for Android Things, and the required changes to enable app to run on embedded things.

Prerequisites

Before you begin building apps for Things, you must:

Get started

To get started quickly, create your app project using the new project wizard:

  • Select Android Things as the only form factor.
  • In order to access new APIs for Things, target Android 8.1 (Oreo), API level 27 or higher.
  • Name the new empty activity HomeActivity.

The new project wizard automatically adds two necessary items to your Android Studio project: a dependency to the Android Things support library and a default launch activity.

Added library

Android Things devices expose APIs through support libraries that are not part of the Android SDK. The new project wizard automatically adds a dependency to the support library to your app-level build.gradle file:

    dependencies {
        ...
        compileOnly 'com.google.android.things:androidthings:+'
    }

The wizard adds <uses-library> to your app's manifest file to make this prebuilt library available to the app's classpath at run time.

Added home activity

An application intending to run on an embedded device must declare an activity in its manifest as the main entry point after the device boots. Note that the wizard applies an intent filter containing the following attributes:

For ease of development, this same activity includes a CATEGORY_LAUNCHER intent filter so Android Studio can launch it as the default activity when deploying or debugging.

<application>
    <uses-library android:name="com.google.android.things"/>
    <activity android:name=".HomeActivity">
        <!-- Launch activity as default from Android Studio -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

        <!-- Launch activity automatically on boot, and re-launch if the app terminates. -->
        <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>
    </activity>
</application>