MIKE BIFULCO: If you're an Android app developer,
you've probably heard about shortcuts.
They give your users the ability to jump
into a specific place in your app
to save a couple of navigation taps
when they've got a specific goal in mind.
Shortcuts are great for a wide variety of use cases--
seeing a list of recent transactions for a shopping app
or pulling up a list of your favorite pizza orders
or YouTube subscriptions.
Lets go over a different kind of shortcut.
We call them dynamic shortcuts.
These are shortcuts which let users jump into your app
to a personalized place or bit of content
based on their past actions.
The primary thing that sets dynamic shortcuts
apart is that they're specific to the person using the app.
For example, if you're building a note-taking app,
you might push dynamic shortcuts based
on the given names of the notes that your users create.
This is notably different from static shortcuts.
Static shortcuts apply to all users of your app,
and you must declare them all in the shortcuts.xml resource
bundled with your app, while dynamic shortcuts are
created based on user behavior at runtime.
If you wanted to create a shortcut to the most recent
note that the user created in your app,
that's a good choice for a static shortcut,
as that sort of functionality would
apply to all of your users.
Your app just has to determine which note the last one is.
But you'd use a dynamic shortcut to launch
the app into a specific note, perhaps determined by its name.
A shortcut to a note named Birthday gift ideas for Natalie
is obviously specific to the individual
who created it previously.
This is a good choice for a dynamic shortcut, which
you could create at runtime when the user interacts
with the note.
Google Assistant can use both types of shortcuts
to enable a voice-driven launch of the app.
For dynamic shortcuts, we call that pushing shortcuts
to Assistant.
Once a shortcut is associated with a built-in intent
and pushed, Assistant will remember it
so the user can make use of it later with a voice command.
Let's take a look at another scenario and some of the ways
that dynamic shortcuts work with Assistant.
I'm a runner, well, an aspiring runner, at least.
I'm just getting back into running after a long time away
and I've created a workout plan in my favorite fitness app
to get me ready to run a half marathon here in a few months.
The fitness app I use lets me save GPS plans
for individual runs of varying lengths, which I use when
I'm running to hit my goals.
This is a great place to use dynamic shortcuts.
As I save a new planned run in the app,
the app can push a dynamic shortcut for that plan,
link it to the start exercise BII,
and provide the name of the plan that I created.
After that, I'll be able to tell Assistant,
"Hey Google, start a 5k flat on Run Dude,"
and it will deliver an Android intent
that the app can use in the running
plan with the same name.
Later on, if I want to update the title for any
of those running plans, Run Dude can
update the dynamic shortcuts to reflect that.
It can also create more as I add new challenging runs
to my workout plan or remove shortcuts
if I no longer need those routes in my training plan.
Super cool.
As apps push shortcuts to Assistant,
Assistant can build up some intelligence
about how an individual user uses the device
and the apps installed on it.
Assistant can use this to offer up
suggestions for queries that might
be relevant to the user at any given point in time.
You can observe these suggestion chips in the Assistant UI
as it's listening.
It's a good idea to push dynamic shortcuts
for each behavior that can be linked to a BII
that your app handles.
This gives Assistant more smarts to provide helpful suggestions.
How cool is that?
Suddenly, my Assistant is offering suggestions
based on my running plans and in-app behavior.
With this kind of help, I'll be crossing
the finish line of that half marathon soon enough.
So armed with a better understanding
of what you might use dynamic shortcuts for, let's
talk about how to actually add them to your app.
For starters, all dynamic shortcuts
must be associated with a BII capability defined in your app.
Check out our built-in intent reference
to find a list of the speech models
that Assistant can recognize.
In this case, I'll use the BII called
Get exercise plan to set up shortcuts for the fitness app
that respond to queries such as, find 5k flat run in Run Dude.
We're going to provide a value used for the BII parameter
exercisePlan.name as a part of the configuration
of our dynamic shortcut.
The name of the run that the user provided, 5k flat,
will be the value.
You'll need two things in order to make
Assistant aware of your dynamic shortcuts.
Firstly, you'll need to add two Jetpack modules to your app.
The Jetpack Core Library has the Shortcut Manager Compatibility
APIs that you'll use to compose and push a dynamic shortcut.
You might already have this in your app,
but be sure to make sure that you've
got version 1.6.0 or later.
You'll also need the Google Shortcuts Integration Library.
This lets Assistant listen in on the changes
to dynamic shortcuts that you make using the Shortcut Manager
API.
You should follow the instructions
and the documentation to get these added to your app.
You'll need to have a BII capability configured
in your shortcuts.xml.
This lets Assistant know which types of voice queries
your app can handle.
Here, I already have a shortcuts.xml file
added to my app and registered in its manifest.
Adding the GET_EXERCISE_PLAN capability
tells Assistant that my app can handle
queries that follow the speech patterns shown in the BII docs.
We're almost there.
Now we just have to add code to actually push
a dynamic shortcut within our app.
We'll want to put this code in a place that
indicates that the user has just interacted with the exercise
plan, perhaps either newly creating it or navigating
to it.
Every app will be different in this respect.
Right here is where we're plumbing up the dynamic part.
By passing our user's given plan name into the shortcut
configuration, we're telling Assistant the words to look
for when the user speaks them aloud in a query.
This line actually pushes the shortcut to Assistant.
Keep in mind that the Shortcut Manager
APIs for dealing with dynamic shortcuts are all blocking,
synchronous APIs.
You should only call them from a background thread or co-routine
and never the main thread.
And that's all there is to it.
Pretty neat.
Now when athletes save a route plan in Run Dude,
we push a dynamic shortcut to Assistant with their custom
route plan name, which means they
can ask for it with a voice command at any time.
And that's it, a quick primer on dynamic shortcuts
for Assistant.
We've also got more great content on the Google
Developers YouTube channel.
Be sure to join our dev community on Reddit,
where you can chat with other actions on Google devs
and stay up-to-date by following us on Twitter.
I'm Mike Bilfulco.
Thanks for watching, and I can't wait to see what you build.