Last active
November 22, 2018 12:13
-
-
Save huihut/3a8a84b8472d59b12d817379bc617eec to your computer and use it in GitHub Desktop.
UWP get Device, OS and App info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://www.suchan.cz/2015/08/uwp-quick-tip-getting-device-os-and-app-info/ | |
https://docs.microsoft.com/zh-cn/windows/desktop/api/winnt/ns-winnt-_osversioninfoa | |
https://social.msdn.microsoft.com/Forums/WINDOWS/en-US/6d754895-36c0-403d-a91d-f0efbc1f36a8/uwphow-to-retrieve-os-version-in-a-universal-app?forum=wpdevelop | |
*/ | |
using Windows.ApplicationModel; | |
using Windows.Security.ExchangeActiveSyncProvisioning; | |
using Windows.System.Profile; | |
... | |
public static class Info | |
{ | |
public static string SystemFamily { get; } | |
public static string SystemVersion { get; } | |
public static string SystemArchitecture { get; } | |
public static string ApplicationName { get; } | |
public static string ApplicationVersion { get; } | |
public static string DeviceManufacturer { get; } | |
public static string DeviceModel { get; } | |
static Info() | |
{ | |
// get the system family name | |
AnalyticsVersionInfo ai = AnalyticsInfo.VersionInfo; | |
SystemFamily = ai.DeviceFamily; | |
// get the system version number | |
string sv = AnalyticsInfo.VersionInfo.DeviceFamilyVersion; | |
ulong v = ulong.Parse(sv); | |
ulong v1 = (v & 0xFFFF000000000000L) >> 48; | |
ulong v2 = (v & 0x0000FFFF00000000L) >> 32; | |
ulong v3 = (v & 0x00000000FFFF0000L) >> 16; | |
ulong v4 = (v & 0x000000000000FFFFL); | |
SystemVersion = $"{v1}.{v2}.{v3}.{v4}"; | |
// get the package architecure | |
Package package = Package.Current; | |
SystemArchitecture = package.Id.Architecture.ToString(); | |
// get the user friendly app name | |
ApplicationName = package.DisplayName; | |
// get the app version | |
PackageVersion pv = package.Id.Version; | |
ApplicationVersion = $"{pv.Major}.{pv.Minor}.{pv.Build}.{pv.Revision}"; | |
// get the device manufacturer and model name | |
EasClientDeviceInformation eas = new EasClientDeviceInformation(); | |
DeviceManufacturer = eas.SystemManufacturer; | |
DeviceModel = eas.SystemProductName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment