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.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
App Actions: Getting Started
15 mins
- Getting Started
- Introducing App Actions
- Understanding the Internal Working of App Actions
- Uploading a Draft App to Play Console
- Adding Your First App Action
- Identifying the Correct BII
- Creating actions.xml File
- Referencing the App Action in Manifest File
- Testing App Actions
- Preparing for Testing
- Using the App Actions Test Tool
- Deploying App Actions
- Where to Go From Here?
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
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:
- 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.
- Stock.kt: File containing the data classes used for parsing the API response.
- 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.
- 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.
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:
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.
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.
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
andactions.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.
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.
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.