Google Assistant Implementation in Android application with app actions
Process flow to create app action in
android native:
Step 1) Create action.xml with Built-In Intent and
defined in androidmanifest.xml
Step 2) Create deep link through firebase dynamic link
SDK
Step 3) Map the Deeplink with built-in Intent in
android action.xml
Step 4) Create the application in Playstore
Step 5) Upload the signed apk in Playstore as save in
draft
Step 6) Open the app action testing tool from latest
android studio after upload the apk in playstore
Step 7) Login the same google account in playstore,
android studio and android device
Step 8) Make sure the check the same Locale language
(en-Us) in Android device and action testing tool
Built-In Intent & Sample Query:
actions.intent.OPEN_APP_FEATURE
- Open
History in <innovationName>
- Open
sale in <innovationName>
- Open
call in <innovationName>
- Open
profile in <innovationName>
- Open
history from <innovationName>
- Show
history from <innovationName>
- Show
profile in <innovationName>
- Open
records in <innovationName>
- Open
<innovationName> my flights
- Open <innovationName> settings
actions.intent.START_EXERCISE
- Start
exercise
- Start
Running in <innovationName>
- Start
Hiking in <innovationName>
actions.intent.STOP_EXERCISE
-
Stop
exercise
actions.intent.CREATE_FLIGHT_RESERVATION
- ·Open <innovationName> and find
flights.
- ·
Open <innovationName> and buy flight
tickets.
- ·
Find flights on <innovationName>.
- ·
Flights to NY on <innovationName>.
- ·
Book a flight to NY on <innovationName>.
- ·
ExampleAirline flights to SFO through <innovationName>.
Step 1) Create action.xml with Built-In Intent and defined in androidmanifest.xml
Create a new android project and goto New -> XML -> App Action Xml file
Step 2) Create deep link
through firebase dynamic link SDK
Open
firebase console and create a new project and goto dynamic link feature and add deeplink
Step 3) Map the Deeplink
with built-in Intent in android action.xml
Paste the below codes in actions.xml in res/xml/actions.xml
<?xml version="1.0" encoding="utf-8"?>
<actions>
<action intentName="actions.intent.OPEN_APP_FEATURE">
<fulfillment urlTemplate="https://deeplink.page.link/open{?featureName}">
<parameter-mapping
intentParameter="feature"
urlParameter="featureName" />
</fulfillment>
<parameter name="feature">
<entity-set-reference entitySetId="FeatureEntitySet" />
</parameter>
</action>
<action intentName="actions.intent.START_EXERCISE">
<fulfillment urlTemplate="https://deeplink.page.link/start{?exerciseType}">
<parameter-mapping
intentParameter="exercise.name"
urlParameter="exerciseType" />
</fulfillment>
</action>
<action intentName="actions.intent.STOP_EXERCISE">
<fulfillment urlTemplate="https://deeplink.page.link/stop"
/>
</action>
<entity-set entitySetId="FeatureEntitySet">
<entity
name="TripSummary"
identifier="Trip" />
<entity
name="Profile"
identifier="Profile" />
</entity-set>
</actions>
Androidmanifest.xml
<meta-data android:name="com.google.android.actions" android:resource="@xml/actions" />
<activity android:name=".AssistantHandleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="deeplink.page.link"
android:scheme="https" />
</intent-filter>
</activity>
Step 4) Create the application in Playstore
Step 5) Upload the signed
apk in Playstore as save in draft
Step 6) Open the app
action testing tool from latest android studio after upload the apk in
playstore
Step 7) Login the same
google account in playstore, android studio and android device
Step 8) Make sure the
check the same Locale language (en-Us) in Android device and action testing
tool
class AssistantHandleActivity : AppCompatActivity() {
lateinit var featureTxt : TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
featureTxt = findViewById(R.id.tv_feature)
intent?.handleIntent()
}
private fun Intent.handleIntent(){
when(action){
Intent.ACTION_VIEW -> handleDeepLink(data)
else -> showDefaultView()
}
}
private fun handleDeepLink(data: Uri?){
when(data?.path)
{
"/start" -> { //Deeplink endpoint url
val exerciseType = data.getQueryParameter("exerciseType").orEmpty()
featureTxt.text = exerciseType
Toast.makeText(applicationContext, "Start Type $exerciseType", Toast.LENGTH_LONG).show()
}
"/stop" -> {
featureTxt.text = "Stop";
// Stop the tracking service if any and return to home screen.
Toast.makeText(applicationContext, "Stopped", Toast.LENGTH_LONG).show()
}
"/open" ->{
val featureType = data?.getQueryParameter("featureName").orEmpty()
featureTxt.text = featureType
Toast.makeText(applicationContext, "Feature Type $featureType", Toast.LENGTH_LONG).show()
}
else ->{
val featureType = data?.getQueryParameter("featureName").orEmpty()
featureTxt.text = featureType
Toast.makeText(applicationContext, "Else Feature Type $featureType", Toast.LENGTH_LONG).show()
}
}
}
private fun showDefaultView()
{
//Default activity goes here
}
}
Issues:
1) Create preview not working in app action test tool
Solution:
Restart the android studio
2) Error while upload the apk/bundle in playstore
"Your uploaded an APK or Android App Bundle which
specifies an actions schema document in its manifest, but a privacy policy is
not provided.
At least one of your APKs or App Bundles contain an
actions.xml file. To continue, accept the Actions on Google Terms of Service in
the Consent section of the Pricing and distribution page."
Solution:
Delete and recreate the application in playstore
3) OPEN_APP_FEATURE works on
test tool only
https://issuetracker.google.com/issues/135714718
Reference:
https://codelabs.developers.google.com/codelabs/appactions/#0
https://developers.google.com/assistant/app/action-schema
https://developers.google.com/assistant/app/reference/built-in-intents/common/open-app-feature
Comments
Post a Comment