Peristiwa
17 Mac, 11 PTG - 21 Mac, 11 PTG
Sertai siri perjumpaan untuk membina penyelesaian AI berskala berdasarkan kes penggunaan dunia sebenar dengan rakan pembangun dan pakar.
Daftar sekarangPelayar ini tidak lagi disokong.
Naik taraf kepada Microsoft Edge untuk memanfaatkan ciri, kemas kini keselamatan dan sokongan teknikal yang terkini.
This article describes how you can use the .NET Multi-platform App UI (.NET MAUI) IAppActions interface, which lets you create and respond to app shortcuts. 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.
The default implementation of the IAppActions
interface is available through the AppActions.Current property. Both the IAppActions
interface and AppActions
class are contained in the Microsoft.Maui.ApplicationModel
namespace.
To access the AppActions
functionality, the following platform specific setup is required.
In the Platforms/Android/MainActivity.cs file, add the OnResume
and OnNewIntent
overrides to the MainActivity
class, and the following IntentFilter
attribute:
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
[IntentFilter(new[] { Platform.Intent.ActionAppAction },
Categories = new[] { global::Android.Content.Intent.CategoryDefault })]
public class MainActivity : MauiAppCompatActivity {
protected override void OnResume()
{
base.OnResume();
Platform.OnResume(this);
}
protected override void OnNewIntent(Android.Content.Intent intent)
{
base.OnNewIntent(intent);
Platform.OnNewIntent(intent);
}
}
App actions can be created at any time, but are often created when an app starts. To configure app actions, invoke the ConfigureEssentials(MauiAppBuilder, Action<IEssentialsBuilder>) method on the MauiAppBuilder object in the MauiProgram.cs file. There are two methods you must call on the IEssentialsBuilder object to enable an app action:
This method creates an action. It takes an id
string to uniquely identify the action, and a title
string that's displayed to the user. You can optionally provide a subtitle and an icon.
The delegate passed to this method is called when the user invokes an app action, provided the app action instance. Check the Id
property of the action to determine which app action was started by the user.
The following code demonstrates how to configure the app actions at app startup:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.ConfigureEssentials(essentials =>
{
essentials
.AddAppAction("app_info", "App Info", icon: "app_info_action_icon")
.AddAppAction("battery_info", "Battery Info")
.OnAppAction(App.HandleAppActions);
});
return builder.Build();
}
After app actions have been configured, the OnAppAction
method is called for all app actions invoked by the user. Use the Id
property to differentiate them. The following code demonstrates handling an app action:
public static void HandleAppActions(AppAction appAction)
{
App.Current.Dispatcher.Dispatch(async () =>
{
var page = appAction.Id switch
{
"battery_info" => new SensorsPage(),
"app_info" => new AppModelPage(),
_ => default(Page)
};
if (page != null)
{
// Assume an app with a single window.
await Application.Current.Windows[0].Page.Navigation.PopToRootAsync();
await Application.Current.Windows[0].Page.Navigation.PushAsync(page);
}
});
}
When you create an app action, either at app startup or while the app is being used, check to see if app actions are supported by reading the AppActions.Current.IsSupported
property.
To create app actions, call the SetAsync method:
if (AppActions.Current.IsSupported)
{
await AppActions.Current.SetAsync(new[] { new AppAction("app_info", "App Info", icon: "app_info_action_icon"),
new AppAction("battery_info", "Battery Info") });
}
If app actions aren't supported on the specific version of the operating system, a FeatureNotSupportedException will be thrown.
Use the AppAction(String, String, String, String) constructor to set the following aspects of an app action:
You can get the current list of app actions by calling AppActions.Current.GetAsync
.
.NET MAUI maklum balas
.NET MAUI ialah projek sumber terbuka. Pilih pautan untuk memberikan maklum balas:
Peristiwa
17 Mac, 11 PTG - 21 Mac, 11 PTG
Sertai siri perjumpaan untuk membina penyelesaian AI berskala berdasarkan kes penggunaan dunia sebenar dengan rakan pembangun dan pakar.
Daftar sekarangLatihan
Modul
Create multi-page .NET MAUI apps with tab and flyout navigation - Training
Use .NET Multi-platform App UI (MAUI) shell to create multi-page applications with tabs and flyout navigation.
Dokumentasi
Learn how to use the .NET MAUI Permissions class, to check and request permissions. This class is in the Microsoft.Maui.ApplicationModel namespace.
Learn how to use deep linking functionality in a .NET MAUI Android app.