Google Assistant App Actions on Android

Dhaval Patel
Mindful Engineering
3 min readMay 26, 2021

Do you ever wonder how google assistant book a taxi for you on ride booking app, make food order from any food app and many more things ? That is done by using google assistant app actions in mobile app.

How to use app actions in your app ?

First find the use case in your app. Find functionality or features which you want to make accessible to user using app actions. If you have food ordering app, finance marketing app, fitness tracking app, or any other apps.

In food ordering app you can directing redirecting particular item screen based on user choice like pizza. In finance app, on based user request you can give market values to user.

In fitness tracking app, you can open tracking activity and get calories values directly. I have riding app in which i can request the ride , open upcoming trips, ongoing trips or completed trips listing in app.

After selecting functionality or feature which you want to open from google assistant. Now we need to check the possibility of that actions in built-in intents from google.

Google Provides many built-in intents for various types like Communication, Food, Travel, Shopping and many more. Also they provide common intents which you can you use anywhere like Open app feature, Get thing, Get account and many others.

Now we have implement android deep links for selected features. Google assistant use deep links to fulfill the intent and pass parameters to the app. Add Host URL and scheme in AndroidManifest.xml of your app like below.

If you are using Navigation Graph, you can deepLink tag from navigation component.

If you are not using Navigation Graph, then you manually handle intent in activity. Based on that you pass data to fragment.

Now when the app filters an intent of the format "https://mi.googlesample.com/completed-trips", it open trip listings with completed trip data. for validating of deep link you can use ADB command line tools.

adb shell am start -a android.intent.action.VIEW -d "https://fit-actions.firebaseapp.com/start"

Now we have to implement BII in app. for that we need to actions.xml in our res/xml folder. which map app functionality with BII for google assistant. We need to add reference of this file in AndroidManifest.xml.

In actions.xml we have to define which actions we want to trigger.

I added Open app feature BII for my app. which can open upcoming, ongoing, completed trips. Open app feature BII come with recommended field name which comes as parameter named “feature”. You instructed Assistant to match feature parameter values to an inline inventory, FeatureEntitySet, defined as an entity-set-reference in the parameter tag. Then we define entity-set with different entities by providing name ,URL and alternate name. You can provide multiple alternate name using array resource. Fulfilment with value “@{url}” with filled with entity-set-reference values. For fallback static fulfilment with URL provided if any entity is not matching. for more different tags which you can use, you can find here.

That’s it. now testing time for that you need to upload signed AAB or APK on google play console in internal testing. after that you can use App Actions Test Tool plugin in android studio.

Note : You may be asked to sign in to Android Studio. Use the same account used earlier with the Google Play Console.

Please find here source code for a sample app.

Happy Coding!

--

--