App shortcuts are helpful to users because they allow you, as the app developer, to present them with extra ways of starting your app. For example, if you were developing an email and calendar app, you could present two different app actions, one to open the app directly to the current day of the calendar, and another to open to the email inbox folder.
Sample
Get started
To access the AppActions functionality, the following platform specific setup is required.
Android
In the Platforms/Android/MainActivity.cs file add the following:
Not all devices support using app actions. You can check if shortcuts are supported using the following code.
var supported =Device.Info.AppActions.IsSupported;
Create actions
App actions can be created at any time, but are often created when an app starts.
// Creates and assigns three app actions to the device's shortcuts.Device.AppActions.Set(newAppAction[]{newAppAction("1","Messages"),newAppAction("2","Recent"),newAppAction("3","Settings")});
Responding to actions
If the application starts up from a "terminated" state with a shortcut click, the shortcut can be found in:
var shortcut =Device.Info.AppActions.Action;
If the application was already running and a shortcut was clicked, the application will fire Device.Info.AppActions.Changed
// attach to shortcut event.Device.Info.AppActions.AppActionChanged+= AppActions_AppActionChanged;// process shortcut click.privatevoidAppActions_AppActionChanged(object sender,System.EventArgs e){AlertBox.Show(JsonConvert.SerializeObject(Device.Info.AppActions.Action));}
Clicking a shortcut on a Windows desktop app will by default open a new Window. Only the new window will receive the AppActionChanged event.