Implementing Dynamic App Shortcuts in Android
Hello and welcome back!
Previously, we talked about Static App Shortcuts. Let’s move on to the second type of App Shortcuts: dynamic shortcuts.
What is a Dynamic App Shortcut?
A Dynamic App Shortcut is an App Shortcut that can be changed (add, update, or remove) programmatically. This type of shortcut is suitable for performing actions that are tailored to the user’s previous actions.
Take the Gmail app below, for example. Take notice that the App Shortcuts displayed are different between when the app is first installed and when you have logged in to your accounts. The two additional shortcuts on the right image are added dynamically based on which accounts you’re logged into.
That’s the power of Dynamic App Shortcuts!
How to Implement Dynamic App Shortcuts?
These are the steps needed to implement dynamic app shortcuts in your app.
1. Adding a dynamic shortcut is very straightforward. Let’s take the Bobobox app, our use case app, as an example. Let’s say that a user has made and paid for a room reservation. We can create a dynamic shortcut for displaying the details of that reservation (Take a note that we can’t make this shortcut static because each user has different reservations).
Create the dynamic shortcut by using
ShortcutManagerCompat like this:
Notice how you can specify one or more Intents that will be called by the shortcut, exactly like Static App Shortcut. Notice also that when using dynamic shortcuts, you can specify the Intents’ flags and extras however you like.
2. The code snippet below shows how you can use the utility object above. In this example, this method will be called whenever users create/update their reservation.
3. And, you’re done! You can test them by running your app and long-pressing the app’s icon launcher like this:
4. When the user has checked out from his/her room, you can remove the shortcut like shown here:
Do you Like this Article?
Leave us some claps 👏 and follow our Medium publication for more articles like this.
And don’t forget to download our app on your Android or iOS and book your first room in Bobobox! 😀