Howdy!! I hope you are very well and safe in your home taking care of your health and your loved ones! 💕 In this time I’m so happy to write about an amazing API recently included in the Xamarin Essentials 1.6, as is the AppActions! This allow us to create shortcuts in our Apps just using Xamarin Essentials! 💚
Besides this amazing update, I invite you to take a look at everything included in Xamarin Essentials 1.6, it will allow you to implement a lot of great functionalities in your Apps, such as MediaPicker, Contacts, Screenshots among others! Enter here to continue reading about it! 🤓
To implement it, follow the instructions added below:
In your AppDelegate.cs add the following code:
In your MainActivity add the following code:
Let’s start adding an icon to our App! (I already have this step ready! 🤓) In case you need information on how to do it, I’ll explain it to you in this post.
Step 1: Adding the menu description actions
To add menu actions, it’s important to understand the required structure. You will see it below and as I like to explain a lot with graphic examples, here I leave one. 😋
Now let’s see the implementation in code 🤓 (In this example, I added the following code in the App.xaml.css ➡ OnStart method)
🎯 Important: For the subtitle is important to know that just will be displayed under the title if is supported by the platform.
Pay attention to some important points:
📔 The icon value must match icons in the corresponding resources directory on each platform.
FeatureNotSupportedException will be thrown, if the action created it’s no supported.
Step 2: Making the actions
When your application starts register for the OnAppAction event. This event is responsible for sending the corresponding information when the user selects a certain action.
📔 First, in the App constructor let’s add the event handle that we’ll be using to catch all the user interaction with the options.
📔 Now, let’s create the
AppActions_OnAppAction event and add a small validation on the corresponding App.
📔 Finally, let’s use the MainThread from Xamarin Essentials. Here you just need to add all the ID options available and the action that you want!
And done! Our shortcuts are added to our Apps! 😎
Thanks for reading 💚💕