Szerkesztés

Megosztás a következőn keresztül:


App information

Browse sample. Browse the sample

This article describes how you can use the .NET Multi-platform App UI (.NET MAUI) IAppInfo interface, which provides information about your application.

The default implementation of the IAppInfo interface is available through the AppInfo.Current property. Both the IAppInfo interface and AppInfo class are contained in the Microsoft.Maui.ApplicationModel namespace.

Read the app information

The IAppInfo interface exposes the following properties:

The following code example demonstrates accessing some of these properties:

string name = AppInfo.Current.Name;
string package = AppInfo.Current.PackageName;
string version = AppInfo.Current.VersionString;
string build = AppInfo.Current.BuildString;

Get the current theme

The RequestedTheme property provides the current requested theme by the system for your application. One of the following values is returned:

Unspecified is returned when the operating system doesn't have a specific user interface style. An example of this is on devices running versions of iOS older than 13.0.

The following code example demonstrates getting the theme:

ThemeInfoLabel.Text = AppInfo.Current.RequestedTheme switch
{
    AppTheme.Dark => "Dark theme",
    AppTheme.Light => "Light theme",
    _ => "Unknown"
};

Get the layout direction

The RequestedLayoutDirection property provides the current layout direction used by the system for your application. One of the following values is returned:

Unknown is returned when the layout direction is unknown.

The following code example demonstrates getting the layout direction:

LayoutDirection layoutDirection = AppInfo.Current.RequestedLayoutDirection;

Display app settings

The IAppInfo class can also display a page of settings maintained by the operating system for the application:

AppInfo.Current.ShowSettingsUI();

This settings page allows the user to change application permissions and perform other platform-specific tasks.

Platform implementation specifics

This section describes platform-specific implementation details related to the IAppInfo interface.

App information is taken from the AndroidManifest.xml for the following fields:

  • BuildStringandroid:versionCode in manifest node
  • Nameandroid:label in the application node
  • PackageNamepackage in the manifest node
  • VersionStringandroid:versionName in the manifest node

Requested theme

Android uses configuration modes to specify the type of theme to request from the user. Based on the version of Android, it can be changed by the user or may be changed when battery saver mode is enabled.

You can read more on the official Android documentation for Dark Theme.