Xamarin.Essentials:应用信息Xamarin.Essentials: App Information

AppInfo 类提供应用程序的相关信息 。The AppInfo class provides information about your application.

入门Get started

若要开始使用此 API,请阅读 Xamarin.Essentials 的入门指南以确保在项目中正确安装和设置库。To start using this API, read the getting started guide for Xamarin.Essentials to ensure the library is properly installed and set up in your projects.

使用 AppInfoUsing AppInfo

在你的类中添加对 Xamarin.Essentials 的引用:Add a reference to Xamarin.Essentials in your class:

using Xamarin.Essentials;

获取应用程序信息:Obtaining Application Information:

通过 API 公开了以下信息:The following information is exposed through the API:

// Application Name
var appName = AppInfo.Name;

// Package Name/Application Identifier (com.microsoft.testapp)
var packageName = AppInfo.PackageName;

// Application Version (1.0.0)
var version = AppInfo.VersionString;

// Application Build Number (1)
var build = AppInfo.BuildString;

显示应用程序设置Displaying Application Settings

AppInfo 类还可以显示由操作系统为应用程序维护的设置页面 :The AppInfo class can also display a page of settings maintained by the operating system for the application:

// Display settings page
AppInfo.ShowSettingsUI();

此设置页面使用户能够更改应用程序权限,并执行其他特定于平台的任务。This settings page allows the user to change application permissions and perform other platform-specific tasks.

平台实现细节Platform Implementation Specifics

应用信息提取自 AndroidManifest.xml 的以下字段:App information is taken from the AndroidManifest.xml for the following fields:

  • 版本 – manifest 节点中的 android:versionCodeBuildandroid:versionCode in manifest node
  • 名称 - application 节点中的 android:labelName - android:label in the application node
  • PackageName:manifest 节点中的 packagePackageName: package in the manifest node
  • VersionString – application 节点中的 android:versionNameVersionStringandroid:versionName in the application node

APIAPI

第 9 频道YouTube 上查找更多 Xamarin 视频。Find more Xamarin videos on Channel 9 and YouTube.