Showing posts with label App Actions. Show all posts

Introduction In this tutorial, we will learn how to create and use app shortcuts in the xamarin forms app using Xamar...

App Shortcuts in Xamarin Forms App Shortcuts in Xamarin Forms

A blog about android developement

App Actions

App Shortcuts in Xamarin Forms

Introduction

In this tutorial, we will learn how to create and use app shortcuts in the xamarin forms app using Xamarin Essentials - AppActions class lets you create and respond to app shortcuts from the app icon. This will allow to navigate to the corresponding page from the app icon.


Coding Part

Steps

  1. Step 1: Creating new Xamarin.Forms Projects
  2. Step 2: Setting up the App Actions in Android and iOS
  3. Step 3: Implementation of App Shortcuts in Xamarin Forms

Step 1: Creating new Xamarin.Forms Projects

Create New Project by selecting "New Project" à "Xamarin Cross Platform App" and Clicking "OK".
Note: Xamarin.Forms version should be greater than 5.0.

Then Select Android and iOS Platforms as shown below with Code Sharing Strategy as PCL or .Net Standard and Click OK.

Step 2: Setting up the App Actions in Android and iOS

    In this step, we will see how to setup the code for Android and iOS.

    Android Setup
  • Add Intentfilter for App Action in your MainActivity.cs class. Refer to the below image.
  • Then add the following logic to handle actions:
  • iOS Setup
  • In the AppDelegate.cs add the following logic to handle actions:

Step 3: Implementation of App Shortcuts in Xamarin Forms

In this step, we will see how to implement the functionality in Xamarin.Forms.

Create App Actions in Xamarin.Forms
  • App Actions can be created at any time, but are often created when an application starts. Call the SetAsync method to create the list of actions for your app.
  • If App Actions are not supported on the specific version of the operating system a FeatureNotSupportedException will be thrown. The following properties can be set on an AppAction:
    1. Id: A unique identifier used to respond to the action tap.
    2. Title: The visible title to display.
    3. Subtitle: If supported a sub-title to display under the title.
    4. Icon: Must match icons in the corresponding resources directory on each platform.
  • When your application starts register for the OnAppAction event. When an app action is selected the event will be sent with information as to which action was selected.
  • Full Code

    App.xaml.cs AppDelegate.cs MainActivity.cs MainPage.xaml.cs

    Result

    Download Code:

    You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.