Android Things Tutorial: Getting Started
Did you ever want to tinker with all those little pins on hardware boards? Well in this tutorial, you’ll learn how to do just that, with AndroidThings! By Dean Djermanović.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Android Things Tutorial: Getting Started
30 mins
- Developing for Android Things
- Getting Started
- Connect the Hardware
- Install Android Things
- Connect to the Internet
- Download and Explore the Starter Project
- Communication with Hardware
- Manage the Connection
- Read from an Input
- Listen for Input State Changes
- Write to an Output
- Connect with Firebase
- Capture the Ring Event
- Notify the User
- Handle Response
- Where to Go From Here?
Android Things is an Android-based operating system which Google manages that enables you to build hardware devices for the Internet of Things (IoT). In the broadest sense, the Internet of Things is a network of connected “things”. This includes everything from microwave ovens to the jet engine of an airplane. If a device has a switch or measures something, chances are you can adapt it, and expose it over an IoT network.
In this tutorial you’ll use Android Things to solve a real life problem by creating an app that simulates a doorbell. In the process, you’ll learn:
- What Android Things is and how it works.
- How hardware and software communicate.
- How to integrate Firebase with Android Things.
Note: This tutorial assumes that you have solid knowledge of Android development. If you’re completely new to Android development, please check out our Beginning Android Development with Kotlin series first. Other things that are used in this tutorial are the ADB, Firebase and LiveData. If you’re not familiar with these concepts please check out our tutorials for them as well.
This tutorial focuses on the using the Raspberry Pi. To complete the exercises, you will need the following hardware:
You will also need to have a Google account and access to a Wi-Fi network that allows for device-to-device communication.
Alternatively, you can complete this tutorial using the Pico Pi based Starter Kit for Android Things. If you are using this board/kit, you have the option of either connecting to your board via a Wi-Fi network/ethernet connection or directly with the USB cord. If you use the USB cord you can skip the connect to the Internet steps of this tutorial. Also, you will need to follow the instructions that come with the kit to assemble it before starting this tutorial.
- A Raspberry Pi 3 Model B and
- A Pimoroni Rainbow HAT for Android Things
- A power supply with a minimum of a 5volt, 2.0Amp rating
- An SD card that is at least 8GB
Note: This tutorial assumes that you have solid knowledge of Android development. If you’re completely new to Android development, please check out our Beginning Android Development with Kotlin series first. Other things that are used in this tutorial are the ADB, Firebase and LiveData. If you’re not familiar with these concepts please check out our tutorials for them as well.
This tutorial focuses on the using the Raspberry Pi. To complete the exercises, you will need the following hardware:
- A Raspberry Pi 3 Model B and
- A Pimoroni Rainbow HAT for Android Things
- A power supply with a minimum of a 5volt, 2.0Amp rating
- An SD card that is at least 8GB
You will also need to have a Google account and access to a Wi-Fi network that allows for device-to-device communication.
Alternatively, you can complete this tutorial using the Pico Pi based Starter Kit for Android Things. If you are using this board/kit, you have the option of either connecting to your board via a Wi-Fi network/ethernet connection or directly with the USB cord. If you use the USB cord you can skip the connect to the Internet steps of this tutorial. Also, you will need to follow the instructions that come with the kit to assemble it before starting this tutorial.
Developing for Android Things
Developing for Android Things is similar to developing mobile Android apps, but there are some key differences. It consists of these four things:
- Hardware – hardware is based on System-on-Module (SOM) design. SOM is a fully integrated component with a CPU, memory, Wi-Fi, Bluetooth and flash storage that is ready to use. You can think of using SOM as using libraries when writing software. Google certified the SOM, and provided a board support package that includes the kernel, drivers and libraries to support Android. With the Android Things 1.0 release, Google announced support for SOMs based on designs from NXP, Qualcomm and MediaTek, certifying them for production use.
- Android for IoT – Android Things is an optimized version of Android that can run with lower compute and storage requirements. Security features are built-in and ON by default. A fundamental part of security are timely, Over the Air (OTA), software updates. This means the device only needs network access with Wi-Fi or Ethernet to get updates, such as stability fixes and security patches which Google provides. Automatic updates are enabled for all devices by default. Because Android Things is optimized for embedded devices, there are fourteen sets of APIs that are currently not supported, including ones relating to telephony.
- Apps and services – with Android Things you can build apps using the rich framework the Android SDK provides, and Google Play Services. You can also easily integrate your apps with popular Google services like Firebase, which you’ll see later, Tensorflow or ML Kit. You can do this by using existing Android client libraries. Since Android Things is Android, you can use all of its languages and tools right out of the box. In this tutorial, you’ll be using Android Studio and Kotlin.
- Android Things console – management console is where you control what exactly goes into your devices. It’s where you get the access to the board support package that Google and board vendors are supporting, where you create full product builds with all of your apps and services included and where you manage releases and update channels over time.
Getting Started
While there are a number of different supported boards, this tutorial focuses on using Raspberry Pi 3 and, to a lesser extent, the Pico Pi. Using one of these two boards allows you to use a peripheral HAT(hardware on top) board with a Raspberry Pi standard pinout. This avoids the need to mess around with soldering, bare wires and breadboards that can make it easy to short out or cause smoke/fire to appear and ruin your Raspberry or Pico Pi. While some makers would consider smoke and fire to be a right of IOT passage, for this tutorial you will simply plug the hat into the Pi.