Xamarin, Xamarin Essentials

Adding Shortcuts with Xamarin Essentials

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! 🤓


Let’s start!

Platform settings

To implement it, follow the instructions added below:

This image has an empty alt attribute; its file name is if_apple-ios-system-platform-os-mac-linux_652586.png In your AppDelegate.cs add the following code:


This image has an empty alt attribute; its file name is if_android_313085.pngIn your MainActivity add the following code:


Let’s 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. 😋

La imagen tiene un atributo ALT vacío; su nombre de archivo es a0c08fa7-52b1-44c9-a035-c445556ff8e5

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 💚💕

Spanish post: https://es.askxammy.com/agregando-shortcuts-con-xamarin-essentials/

Reference: https://docs.microsoft.com/en-us/xamarin/essentials/app-actions?context=xamarin%2Fxamarin-forms&tabs=ios?WT.mc_id=DT-MVP-5003353

Tagged , ,

4 thoughts on “Adding Shortcuts with Xamarin Essentials

  1. Another great post Leomaris, thank you.

    On the back of this I have implemented a couple of AppActions in the apps I am building for a client.
    They work great on iOS, but on Android, selecting an action displays and App Isn’t Installed toast message.
    Just wondering if you’ve seen that before?

    Thanks
    Jonathan

    1. Hello Jonathan !! Thank you! 💚💕

      It has never happened to me, could you leave me a screenshot to see it in detail, please?

Leave a Reply

Your email address will not be published. Required fields are marked *