Google Assistant Slices for Android — part 2
In a previous article, we have seen how to add Google Assistant support to your App. Now it is time to get a step further and provide a beautiful user experience right into Google Assistant, so that the user don’t have to launch the app to interact with it. This will be done thanks to Slices.
What are Slices?
Slices are small card of UI, that Google Assistant display to provide a richer user experience. They can contains information pulled from APIs, as well as images and action buttons.
They are a way of interacting with your app without starting it full screen, the user experience is contextual to Google Assistant and conversational.
Slices are using basic UI blocks such as list, header, row, images, buttons… The developer can build the UI in a declarative way a bit like Jetpack Compose.
Slices offer a quick way to access feature of the app, so keep it simple.
Declaring the Slice in Shortcuts.xml
Similarly to App Action, Slices need to be declared in
shortcuts.xml Google offer a large set of pre-defined actions/captilities, please check my previous article.
Inside a capability, you can add a child node
slice and provide a
url-template this template will be used to trigger the Slice.
Notice it is recommended to use “content” as scheme.
Creating the SliceProvider
The Slice Provider is in charge of creating a Slice object given an URI (url-template above).
You should extends
SliceProvider and implement 2 methods:
- onBindSlice(), it takes a Uri, and what you need to do is map this Uri with your slice and return the Slice
- onCreateSliceProvider(), you can do preliminary tasks, but…