Introduction: How to Connect the Android Application With AWS IOT and Understanding Voice Recognizing API

This tutorial teaches the user how to connect the Android Application to AWS IOT server and understanding voice recognition API which controls a Coffee Machine.

The application controls the Coffee Machine through the Alexa Voice Service, each App's component and voice commands triggers different skills created on AWS by publishing on AWS IOT topics.


  • Basic knowledge on Android development considering that the base code is attached to this tutorial, but it's necessary to make some changes to adapt to the user's account and some parameters.
  • An active AWS account.

This project is divided into 2 steps: Preparing the environment with the Android Studio Application and communication with AWS IOT server and Understanding the Voice Recognition Functionality.

Step 1: Preparing the Environment With the Android Studio Application and Communication With AWS IOT Server

This step uses an Android Application code already configured attached to this tutorial, but it's necessary to have installed and configured the Android Studio tool. To download it, click on this link and follow the instructions provided by the official documentation.

To create an Android Studio Application by your own and connect with AWS IOT server, please check this Instructable.

Now, to use the the source code available here please follow this steps:

    1. Download the coffee machine code available on the end of this step.
    2. Open the Android Studio Tool.
    3. Click on "Import project (Eclipse ADT, Gradle, etc.)".
    4. Select the downloaded code from the first topic.

    To modify the application and enable AWS IOT communication:

    1. Select Android on the structure option on the left upper side of the window.
    2. Open the "AWS Connection" file available on this path: app/java/
    4. Set them according to the your AWS account after setting the identity pool with Amazon Cognito.

    The communication of the application with the AWS IOT server is done through topics, that works as communication channels. On this topics occurs subscriptions and publishes that are responsible to control and monitor the state of different types of IOT devices. On this example the application subscribe and publish to the following topics which are located on the "Constants" file(app/java/ TOPIC_TURN_ON_OFF, TOPIC_SHORT_COFFE, TOPIC_LONG_COFFE, TOPIC_LEVEL_COFFEE, TOPIC_LEVEL_WATER, TOPIC_GLASS_POSITION, TOPIC_UPDATE, TOPIC_ERROR.

    On this example the topics controls and monitors a coffee machine.

    Step 2: Understanding Up the Voice Recognition Functionality

    The voice recognition functionality is about converting user's voice commands into text and sending it to the AWS IOT server. This converting functionality is provided by a Google API named SpeechRecognizer. To use it it's necessary to import the SpeechRecognizer class (documentation here). This class is already imported on the source code from the Step 1.

    The voice recognition is activated by pressing a speech button (microphone image), referenced by the image button mSpeechButton.

    The command's treatment are located on the event onActivityResult, which receives the user's voice, converts into text and then choose which component will be activated. On this example: when the user says "Turn on the coffee machine", the application enables the switch that controls the coffee machine power, by enabling it, the application publish into the AWS IOT topic a message("1") indicating that the coffee machine should be on.

    Step 3: Conclusion

    After these steps the application is ready to connect to AWS IOT, publish and subscribe to topics through voice commands and the UI components.

    If you have any doubts about the certificates or the application, please check the following links: