Very often we want ways to improve our apps user experience to make users more productive and comfortable using it, often we see that by pressing an app icon it displays a menu of quick options, which is a pretty handy and quick improvement if used wisely for relevant actions. This concept has different names in Android/iOS, in Android, it is known as Shortcuts and it’s available from android 7.1, and in iOS is called QuickActions and it is available from iPhone 6s (iOS 9). In this article, I’m going to show you how to add this to your Xamarin Forms apps.
Looking at ways to do this, I found some great articles by James explaining how to do it on Android and Gerald on iOS. I also found a much simpler way by using the AppShortcuts Plugin by @AdenEarnshaw.
The result:
Let’s do it step by step
1.Install the AppShortcut plugin in your Forms/Android/iOS projects
2. In your iOS project (AppDelegate.cs) add the following code
3. In your Android project (MainActivity.cs) initialize the plugin and add some app link information
Copy code here.
4. In your Xamarin Forms project add the shortcuts
In this sample, I will do it in the App.xaml.cs file.
The AppShortcuts plugin has these main features:
- IsSupported: Check if shortcuts are supported.
- AddShortcut: Adds a new shortcut.
- RemoveShortcut: Deletes an existing shortcut.
- GetShortcuts: Get all the shortcuts
When creating a new shortcut these are the main properties:
–Label: The shortcut’s name
–Description: The shortcut’s description
-Icon: The shortcut’s icon. The plugin has a list of predefined icons you can use like Contact, Share, Home, Favorite, Confirmation, etc, but you can add a custom one (Check more information here).
-Uri: This is the most important one since it’s what we get when opening the app from a shortcut and let us know where to navigate when selecting this shortcut. In Android is important that the AppShortcutUriBase matches the DataScheme/DataHost specified in the MainActivity IntentFilter.
After adding them it will look like this:
5. Adding the navigation when tapping the shortcut
The last step is to add the navigation when the user taps on a shortcut, to do that in our App.xaml.cs file we just have to implement the method OnAppLinkRequestReceived and navigate according to the URL received.
The full code:
That’s all. You can check the full source code here.
Happy coding!