App Actions: Getting Started

App Actions allow Google Assistant to access your app and launch specific actions within the app. This tutorial teaches you how to implement App Actions for your app so users can interact with your app directly through Google Assistant. By Anshdeep Singh.

Leave a rating/review
Download materials
Save for later
Share

What’s the first thing you do when you have a pizza craving? Do you say, “Hey, Google, order my favorite pizza”? This is just one of the ways Google Assistant has made our lives more efficient. Today, Google Assistant is available on a wide variety of Android devices, ranging from smartphones and tablets to watches — and even cars! As a developer, you can use Google Assistant for your own app using App Actions.

App Actions let you open specific features of your app using Google Assistant. Near the end of 2020, Google introduced 30 new intents to build your App Actions, bringing the total to over 60.

In this tutorial, you’ll learn how to add App Actions to an app named StockTracker. The app fetches the latest stock quotes from the internet with the help of a free and public API. Along the way, you’ll learn about:

  • What App Actions are
  • How App Actions work
  • Adding your own App Actions
  • Testing your App Actions
  • Deploying your App Actions
Note: This tutorial assumes you’re familiar with the basics of Android development in Kotlin. You should also have some familiarity with deep links. If you don’t, check out our Deep Links in Android: Getting Started tutorial. You’ll also need a physical device running API 21 or higher to test App Actions.

Getting Started

Download the starter project by clicking the Download Materials button at the top or bottom of this tutorial. Open Android Studio and import the starter project.

Take a moment to familiarize yourself with the code. You’ll see the following classes:

  1. MainActivity.kt: Home screen of the app, which allows users to enter their favorite stock symbol. It also handles the deep links triggered by App Actions.
  2. Stock.kt: File containing the data classes used for parsing the API response.
  3. StockApiService.kt: File containing all the networking-related code, including the GET endpoint used to fetch stock quotes. It also exposes a retrofit object used in StockQuoteActivity.kt.
  4. StockQuoteActivity.kt: Second screen of the app, which displays the latest information on the selected stock. In this class, Coroutines fetch data from the network asynchronously.
Note: If you’re not familiar with Coroutines, check out our Kotlin Coroutines tutorial.

Before you build and run the app, you need to add your own API key. Get your API key from Alpha Vantage Support. Once you have the key, open StockQuoteActivity.kt and paste it inside the empty quotes to assign the value to the constant named API_KEY.

Now you’re all set. Run the app, and you’ll see the screen below:

Main Screen of Stock Tracker app

Enter the ticker symbol of your favorite stock (e.g., GOOG) and tap GET QUOTE. A new screen shows your selected stock’s latest quote.

Stock Tracker screen showing results for GOOG stock

Note: Make sure you’re connected to the internet to the view the stock quote.

So, now you’ve got an app that can check stock quotes when you type in a symbol, but wouldn’t it be cool if you could just ask it instead? That’s where App Actions come in! :]

Introducing App Actions

App Actions are shortcuts to your app. They can launch different features of your app with the help of Google Assistant. You can deep link into your app with a simple voice command like, “Hey, Google, tell me the stock quote of GOOGL in Stock Tracker”.

App Actions can also display any information from your app directly in the Google Assistant conversation dialog. You don’t need to open your app explicitly, you can just ask Google Assistant to fetch it for you without switching the current context.

Three gears artistically illustrating that there are parts working together inside the built-in intents.

Understanding the Internal Working of App Actions

App Actions work on the concept of intents. Intents are objects that can request actions from different components of an app. There are two types of intent used for invoking different App Actions:

The complete list of built-in intents is available in the official index. You need to specify the built-in intent you want to use for your app in the actions.xml file.

The main difference between a built-in intent and a custom intent is that for a custom intent you have to specify additional query patterns to include the things that the user might say. You need to specify the different query patterns inside a string array. For each custom intent you implement in your app, there can be a maximum of 100 query patterns.

  • Built-in intents (BIIs): As the name suggests, BIIs are a set of intents provided by Google to support common app functionalities. There are different categories of BIIs. Some examples of built-in intents are actions.intent.GET_NEWS_ARTICLE, actions.intent.CREATE_CALL and actions.intent.ORDER_MENU_ITEM.

    The complete list of built-in intents is available in the official index. You need to specify the built-in intent you want to use for your app in the actions.xml file.

  • Custom intents: Although more than 60 built-in intents are currently available, some features of your app may require a functionality that’s not yet available. To handle this situation, you can use custom intents.

    The main difference between a built-in intent and a custom intent is that for a custom intent you have to specify additional query patterns to include the things that the user might say. You need to specify the different query patterns inside a string array. For each custom intent you implement in your app, there can be a maximum of 100 query patterns.

When you add an intent for your App Action, Google Assistant matches the user query with your built-in (or custom) intent. It extracts the intent parameter, passes it to the defined fulfillment for that intent and then deep links the user into the app.

Note: The app should already handle the deep links that Google Assistant will invoke.

Now that you know how App Actions work, it’s time to upload the app.

Uploading a Draft App to Play Console

Before you start adding App Actions, you need to upload a draft version of your app to Play Console. This allows you to use the App Actions Test Tool, described later in this tutorial.

Note: This tutorial assumes you already have a Google account with access to Play Console.

First, open app/build.gradle and change applicationId to something unique. For example, you can set applicationId to be com.youruniquename.android.stocktracker. This will prevent issues when uploading your app.

Next, build your signed app in Android Studio and upload it to Play Console as an internal release.

Note: If you’re new to publishing an app, check out our App Distribution tutorial. You don’t need to roll out the full internal release. Just upload the signed APK and save it as a draft version once the APK has been uploaded successfully.