App information
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:
- Name — The application name.
- PackageName — The package name or application identifier, such as
com.microsoft.myapp
. - VersionString — The application version, such as
1.0.0
. - Version — The application version, as a Version object.
- BuildString — The build number of the version, such as
1000
. - RequestedTheme — The detected theme of the system or application.
- PackagingModel — The packaging model of the application.
- RequestedLayoutDirection — The requested layout direction of the system or application.
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:
- BuildString —
android:versionCode
inmanifest
node - Name —
android:label
in theapplication
node - PackageName —
package
in themanifest
node - VersionString —
android:versionName
in themanifest
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.