Internet of Things with Android
What is Android Things?
Android + Internet Of Things = Android Things
Android Things makes developing connected embedded devices easy by providing the same Android development tools, best-in-class Android framework, and Google APIs that make developers successful on mobile.
Android Things is Google’s Android-based Internet of Things Initiative.
On December of 2016, Google announced Android Things. A modified version of the Android all we know, for IoT devices.
Apps for embedded devices bring developers closer to hardware peripherals and drivers than phones and tablets. In addition, embedded devices typically present a single app experience to users.
Android Things extends the core Android framework with additional APIs provided by the Things Support Library.
Android Internet of things supports only three IoT devices:
- Intel Edison
- NXP Pico
- Raspberry Pi 3
The list, by now, is quite limited but the OS is still in the preview version so more devices will be added in the future.
How to Install Android Things
Now we know what is Android Internet of things known as Android Things we can start installing it. In this article, we will use Raspberry Pi 3 as a development board. What do we need?
This is the list of things we need to get started with Android Things OS:
– Raspberry Pi 3
– Micro SD Card 8 Gb or more
– Windows or OS X
At the beginning, it is necessary to format the SD card using FAT 32. If you are using a Mac, go to Disk Utility and format the card:
Once you have your board wired together, it’s time to write your first app.
All done. You are ready to install the developer preview image. Download the image for Raspberry. Once the download is ready, we can install it:
The BSD number is the number we are looking for. In this case, n=1. During the installation process, you don’t have messages and you have simply to wait until the process is complete. At the end, you get a message saying that the disk is unreadable, it is ok, it works!
If you are a Linux user, please read the comment below (made by Dimitris) to know how to install it.
It is time to insert the new OS disk into your Raspberry Pi.
Verify Android Things installation
Finally, we can verify if the installation is correct powering on the Raspberry Pi. You can use a USB cable connected to your PC to start Raspberry. At the beginning, you need to connect Raspberry to the LAN using a cable and you need an HDMI cable to connect the board to a TV or monitor. If you don’t want to use an HDMI cable you can use Vysor a Chrome plugin.
Android Primary App Setup
Android Things requires projects to be built with a minimum of SDK 24. You can start this tutorial by creating a new project with that minimum requirement and an empty Activity.
When your base project has been created, open your app module’s build.gradle file. Under the dependencies node, include the Android Things library. At the time of this writing, the library is still in developer preview one.
Next, open your AndroidManifest.xml file. You will need to declare that your app uses the Android Things library by adding the following line within your application node.
The final thing to do in your manifest file is add an intent-filter to your MainActivity node that lets your device know that it should launch this Activity on startup. Because Android Things launches apps at startup, you will generally only want one app installed on a device at a time.
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
Once you’re done with the manifest, you can open MainActivity.java, as this is where the core logic for your first Android Things project will occur. The object that will instantiate your input and output connections is called the PeripheralManagerService, so let’s start by getting a reference to it in onCreate().
PeripheralManagerService service = new PeripheralManagerService();
Now that you have your PeripheralManagerService, let’s do one more thing before digging into writing our control code. Earlier you wired all of your components together to the board using specific pins. In order to control the peripherals that you have attached to these pins, you will need to know the name of each pin on your board. You can print a list of each component using the PeripheralManagerService like so:
Log.e(“AndroidThings”, “GPIOs: ” + service.getGpioList() );
Now, you can start First Android Application with IoT project as we will see in the next blog.
A few days later, I can say that Android Things is an interesting IoT OS based on Android Apps. This is very important & useful because the development process is the same used for an Android app. Developers can reuse the Android knowledge and experience for developing Android IOT Apps. Of course, Android Things is still a developer preview so many things could change but the beginning is very promising.