A couple of weeks ago Google announced Android Things, which brings official Android support to popular IoT devices like Raspberry Pi 3, Intel Edison, or NXP Pico.

This means that you can use all the Android tools you know and love to start building apps that run on a whole new category of devices. In particular, you can start using all Mapbox Android Services (directions API, distance API, geocoding API, etc) in your Android Things projects today.

To show you how, I’ve built a simple app that uses some inexpensive electronics to query Mapbox APIs. This is all you’ll need:

  • A Raspberry Pi 3
  • The Pimoroni Rainbow HAT for Android Things
  • A small speaker (or a headset if you don’t have one)

In this demo, I’m connecting each button in the Rainbow board with our Android SDK. There are three actions that you can take: get your commute time from our Directions API (button A), find interesting places nearby from our Geocoding API (button B), and get our latest news from this blog’s RSS (button C). The green and red LEDs will confirm that your network request is taking place. The code for the app, together with photos of the set up, can be found in this repo.

I also wanted to do voice input, like a mini-Alexa, but unfortunately USB peripherals (like the microphone) aren’t supported in the current Dev Preview

Everything in the app will look familiar to any Android developer. For example, the code runs within an Activity and clicking a physical button looks like a regular OnClickListener set up:

buttonGpio.registerGpioCallback(new GpioCallback() {
	@Override
	public boolean onGpioEdge(Gpio gpio) { // Button was clicked }
}

In order to make the device talk, I’m simply using the core Android android.speech.tts.TextToSpeech engine. And to use Mapbox Android Services there’s nothing you need to change: all code samples from the website will work out of the box (just keep in mind most IoT devices don’t have a screen!).

I hope you find Android Things as fun as I do, let me know if you build any IoT projects with Mapbox.