Add a voice assistant to an Android App(Java and Kotlin)

Process involved in building a voice assistant for an Android app

You can create a voice assistant or a chatbot for an Android app written in Java or Kotlin using the Alan Android voice SDK. In this tutorial, let’s create a simple Android app, integrate a voice assistant using Alan, and then test in on a device. Once the process is completed, the app will allow users to tap on the interact with the voice assistant.

From this tutorial you will learn

  • How to add a voice assistant to an Android app
  • How to write simple voice commands for an Android app

Prerequisites before you get started

  • Firstly, sign up for Alan Studio.
  • Now, create a project in the Alan Studio.
  • You need set up the Android environment and make sure that it is functioning properly. For details, see Android developers documentation.
  • Ensure that the device is connected to the Internet so that the Android app will be able to communicate with the Alan Cloud to run the voice scripts.

Step 1: Create a basic Android app

Let’s create a basic Android app with a single screen in this tutorial.

  1. Open the IDE and select to start a new Android project.
  2. Select Empty activity as the project template. Then click Next.
  3. Enter a project name (for example, myapp) and select the language: Java or Kotlin. Then click Next.
  4. Click on Finish.

Step 2: Integrating the Android app with Alan

Now, let’s do the following to add the Alan button to the Android app.

  1. Open the build.gradle file at the module level.
  2. In the dependencies block, add the dependency configuration for the Alan Android SDK.
//build.gradle file at the module level
dependencies {
//Add Alan SDK dependency
implementation 'app.alan:sdk:4.7.15'

3. Then sync the project with the gradle file. Below is how your build.gradle file should look like:

4. Too add the XML layout for the Alan button to the main app activity, open the main_activity.xml file and add the following to it:


Below is how your main_activity.xml file should look like:

5. Add the alanConfig object to the app. This object describes the parameters that are provided for the Alan button. Now, open the or MainActivity.kt file and add the following code to the MainActivity class:

Below is the Java script:

// file
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
// Alan button
AlanButton alanButton = findViewById(;

// Alan config object
AlanConfig alanConfig = AlanConfig.builder()

Below is the Kotlin script:

//MainActivity.kt file
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Alan config object
val config = AlanConfig.builder()

6. To setProjectId, add the Alan SDK key for our project. In the Alan Studio, at the top of the code editor click Integrations and copy the key value from the Alan SDK Key field to get the key.

7. In the or MainActivity.kt file, import the necessary classes. Below is how your main activity file should look like:

8. Now, run the app.

After the app is built, it will be launched on the connected device. Tap the Alan button and say: Hello world.

Alan will not give an appropriate response if you try to ask: How are you doing?. The voice script in the Alan Studio does not contain the necessary voice commands.

Step 3: Adding voice commands to interact with Alan

To interact with Alan let’s add some voice commands. Open the project in the Alan Studio and in the code editor, add the following intents:

intent (`What is your name?`, p => {`It's Alan, and yours?`);
intent (`How are you doing?`, p => {`Good, thank you. What about you?`);

Now, tap the Alan button and ask: What is your name? and How are you doing? Alan will give respond with the intents we have provided.

Here’s what you can do next

Now, you can proceed with building a voice interface with Alan. Look into some helpful resources listed below:

This content is originally taken from the Alan documentation at




Alan is a B2B Voice AI platform for developers to deploy and manage Voice Interfaces for Enterprise Apps.

Love podcasts or audiobooks? Learn on the go with our new app.

Migrating to View Binding in FlashScore

Flutter in multiple IDE (Android, IntelliJ, VSCode) for macOS

Feature: Dodging Enemy

A look at an Android bot from unpacking to DGA

Android: How to use MockWebServer for Edge-cases Test, UI Test, and Unit Test together?

Racing In Car Download

Writing an XML style checker with Clikt

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alan AI

Alan AI

Alan is a B2B Voice AI platform for developers to deploy and manage Voice Interfaces for Enterprise Apps.

More from Medium

Creating Android app with all social logins and authentications with 3 simple steps

Ads Adapter Wrapper for Android Application

Custom Android Studio Plugin with IntelliJ-platform-plugin-template

Guide to integrate Huawei Ads Kit in Banking app (Kotlin)