UWP apps get all kinds of systems, user information (1)-basic information about devices and systems, app package information, user data account information, and user account information

Source: Internet
Author: User
Tags old windows



In application development, developers often need to obtain some system, user information for data statistics telemetry, problem feedback, user identification and other functions. This article is intended to describe ways to get some common system, user information in a Windows UWP app. Sample project code can be found on Github:


Https://github.com/validvoid/UWP-SystemInfoCollector


Because the content is more involved, this article will be divided into several expansion. This article describes the basic information about acquiring devices and systems, application package information, user data account information, and user account information.



Original blog Read address: http://validvoid.net/uwp-system-info-collect-1/


Analyticsinfo

 device.



ThroughAnalyticsInfothe properties in the classVersionInfowe can get the device type and operating system specific version of the current app running device. A property of type AnalyticsversioninfoVersionInfocontains two members:


    • Devicefamily
    • Devicefamilyversion


DeviceFamilyThe return value type of the property is a string. The device type information it provides is extremely important and is used in almost all UWP development. Usually we will implement the responsive design of the application based on the device type information returned by this property. For example, when you return "windows.desktop" to indicate that the app is running on desktop Windows 10, the app renders a PC-side interface that is appropriate for mouse keyboard operations; When you return "windows.mobile" to indicate that the app is running on Windows 10 on the mobile side, the app should When rendering the mobile-side small screen interface suitable for touch screen operation.



DeviceFamilyVersionThe return value type of the property is also a string. The return value indicates the specific version number of Windows that the current device is running. But the return value obtained directly from this property is a long number shaped like "2814750460870692". If you want to get a version number in the form of a readable "major.minor.revision.build", you need to convert this number to 16 and then convert it to a readable version number.






C # code that formats the version number:


stringSV =AnalyticsInfo.VersionInfo.DeviceFamilyVersion; ULONGv =ULONG.  Parse (SV); ULONGV1 = (V &0xffff000000000000l) >> -; ULONGV2 = (V &0x0000ffff00000000l) >> +; ULONGV3 = (V &0x00000000ffff0000l) >> -; ULONGV4 = (V &0X000000000000FFFFL); stringVersion = $"{v1}. {v2}. {v3}. {v4}";


Running the sample code will be output similar to the following:


Device Analytics InfoDeviceForm: Unknown  DeviceFamily: Windows.Desktop  DeviceFamilyVersion: 2814750460870692  Reconstructed OS Version: 10.0.10586.36


It should be noted that if you intend to perform data statistics and analysis work through devicefamilyversion, do not format the original devicefamilyversion return value in a readable form in your app's client code. According to Microsoft's official MSDN explanation,AnalyticsInfo.VersionInfodesigned to provide telemetry and logging with an opaque version number string value, the best practice is to pass the original value back to the server and, if necessary, perform the work of formatting parsing on the server side.



In addition, theAnalyticsInfoproperties in the class are notDeviceFormspecific and return "Unknown" in both the PC and the Windows mobile device. Only this property is described in the MSDN documentation as "Gets the device form."


Resource Qualifier


Windows.ApplicationModel.Resources.Core.ResourceContextClass encapsulates the resource qualifier (qualifiers) that may affect the resource selection. These resource qualifiers affect the selection of resources required for the application to run. Querying resource qualifiers and making appropriate matching optimizations can also help improve the user experience.



To get the resource qualifier for the current app, we need to call theResourceContext.GetForCurrentView()method to get the current app view's resource context and then access the properties in itQualifierValues. The type of theQualifierValuesproperty isIObservableMap<string,string>, and the corresponding qualifier value can be obtained by the key name.



The following are the possible resource qualifier names and corresponding values listed in the MSDN documentation:


Resource Qualifier Possible values Description
Language such as "en-US" This qualifier name can be mapped to a string value that represents a language, for example, "en-us" for U.S. English.
Contrast Standard This qualifier name can be mapped to the current contrast setting value.
High
Black
White
Scale 80 This qualifier name can be mapped to a value that represents the display scale as a percentage.
100
120
140
150
160
180
225
Homeregion such as "021" This qualifier name can be mapped to a string value that represents a range, for example, "021" for North America.
Targetsize such as "256" This qualifier name can be mapped to a string value that represents the target size, for example, "256".
LayoutDirection LTR This qualifier name can be mapped to a value in the current layout direction.
Rtl
Ttbltr
Ttbrtl
Configuration This qualifier name can be mapped to a string value that represents a configuration.
Alternateform This qualifier name can be mapped to a string value that represents a replacement form.
Dxfeaturelevel DX9 This qualifier name can be mapped to a level that represents the DirectX feature.
DX10
DX11


ForResourceContextmore usage of classes, you can refer to the MSDN documentation ResourceContext type.


Get current app Package information


The Windows.ApplicationModel.Package type is responsible for providing information about the app package. To get the package object instance for the current app, you can get it through the ' package.current ' property. Once we get the package object for the current app, we can get further information on the following:


    • DisplayName Gets the display name of the package.
    • Installeddate gets the time that the package was installed or last updated.
    • Installedlocation Gets the installation location of the package. The return value is ofStorageFoldertype.
    • Isbundle Indicates whether the package is a bundle collection package.
    • Isdevelopmentmode Indicates whether the package is installed in development mode.
    • Isframework Indicates whether there are other packages that declare the package as a dependency.
    • Isresourcepackage Indicates whether the package is a resource bundle.
    • The logo gets the location of the package logo file. The return value is ofUritype.
    • Publisherdisplayname Gets the package Publisher display name.
    • InstallDate gets the time when the app package was first installed. This property is not implemented on Windows 10. It used to be only valid for Windows Phone 8.


In addition to the above attributes, thePackageclass provides three important attributes: Id, Status, and dependencies.



IdThe PackageId property is of type. This property provides a variety of information about the current package Id, including:


    • Architecture gets the corresponding processor schema for the current package.
    • Familyname gets the Family Name of the package. such as "32b04fa8-6b7b-4ed9-8a9b-eade01a24207_hpzxbeh1zj56g"
    • FullName gets the full name of the package. such as "32b04fa8-6b7b-4ed9-8a9b-eade01a242071.0.0.0x86__hpzxbeh1zj56g"
    • Name gets the package name. such as "32b04fa8-6b7b-4ed9-8a9b-eade01a24207"
    • Publisher gets the package publisher. such as "Cn=validvoid"
    • PublisherID Gets the package publisher ID.
    • ResourceId gets the resource ID of the package.
    • Version gets the package versions. The return value is aPackageVersiontype that can further format the output string.
    • Author gets the package author. Windows Phone only, not valid on Windows 10.
    • ProductId gets the property value of the packageProductID. Windows Phone only, not valid on Windows 10.


StatusThe Packagestatus property is of type. This type provides aVerifyisOK()way to determine whether the current package is in good condition and can be used. The method validatesPackageStatusa series of properties in order to determine whether the package is available.PackageStatusThe following properties are included:


  • Dataoffline indicates whether the data used by the current package is offline. For example, this property returns True when the applied data is installed on removable media such as an SD card, and when the media pops up, the data is offline.
  • Dependencyissue indicates the dependency status of the package. This property returns True when one of the dependencies of the current package encounters an exception. The current package will not be available until all dependencies on the current package resolve the issue.
  • Deploymentinprogress indicates whether the current package is being consumed by the deployment process. For example, this property returns True when the package is being updated.
  • Disabled indicates whether the current package is disabled. Packages can be disabled via Packagemanager.setpackagestatus, or enabled via Packagemanager.clearpackagestatus.
  • Licenseissue indicates whether the current package has an authorization issue. For example, this property returns True when authorization is lost or expired. The current package will not be available until all licensing issues are resolved.
  • Modified Indicates whether there is a content modification issue with the current package. For example, this property returns True when some files are missing from the package.
  • Needsremediation indicates whether the current package needs to be remediated. For example, when,,,NotAvailableLicenseIssueModifiedTamperedOne or more of the properties indicate that the current package has an exception condition, this property is true.
  • Notavailable indicates whether the current package is unavailable. For example,DataOfflinewhenDisabledPackageOfflineone or more of the properties in indicates that the current package has an exception condition, this property is true.
  • Packageoffline indicates whether the current package is offline or inaccessible. For example, this property is true when the pack documentation piece is installed on removable media, such as an SD card, and the media is removed.
  • Servicing indicates whether the current package is in a occupied state.
  • Tampered indicates whether the current package is in an infected state. One possible reason for changing the property back to true is that third-party anti-virus software marks the current package for malicious programs.


Dependenciesproperty is aIReadOnlyList<Package>type that can be used to get all the dependencies of the current package. Note This property is only used to obtain dependencies for the Windows store app package. To get a dependency on a desktop app package, you use the Win32 function Getpackageinfo.



Refer to thePackagesample code on Github for specific usage.


Enumerate the deployed app packages on a Windows mobile device


Windows.Phone.Management.DeploymentNamespaces provide a series of types for controlling application deployment features, where the Installationmanager type is responsible for the installation management of the application package. We canFindPackagesForCurrentPublisherget the application package deployment of the same publisher installed on the current Windows mobile device through the method. The return type of the method isIEnumerable<Package>that we can further retrieve the return value to get the details of a specific app package or even launch these apps.



It's worth noting thatWindows.Phone.Management.Deploymentonly works on Windows mobile devices, so when used in a UWP app, you need toAnalyticsInfo.VersionInfo.DeviceFamilydetect the current device type and choose whether to invoke the method under that namespace. In addition, other methods provided in the ' Installationmanager ' class requireID_CAP_OEM_DEPLOYMENTspecial permissions to function properly, so the general developer is not able to use it.


Get User Data account information


What is a user data account? For example, if you've ever used an Android system, you'll see a setup section called "Accounts" (Accounts) in your Android system settings that lists the current system logins for Gmail, Outlook, Office, Exchange, Accounts registered for various applications such as Weibo. These accounts are user data accounts.Windows.ApplicationModel.UserDataAccountsnamespaces define related types and enumerations for controlling user data account information such as messages, appointments, calendars, and so on. Where the Userdataaccount type represents a user data account that is used to access data such as mail, contacts, calendars, and so on. The Userdataaccountmanager type provides APIs for interacting with user data accounts. Userdataaccountstore represents the storage area of the user data account. This article focuses on how to obtain some commonly used information through the Windows Store App API, so there is no manipulation of the contents of the user data account. Just focus on how to get some data.



To use theUserDataAccountsrelevant API, you are required to declare one or more of the features in the manifest file, such as Contacts (contacts), appointments (appointments), mail (email), and so on.



Suppose we want to enumerate all the user data accounts that are logged on to the current system and output the relevant information for those accounts, first we needUserDataAccountManager.RequestStoreAsyncto ask the system for the storage area of the user's data account through the method. The method accepts a parameter of the Userdataaccountstoreaccesstype enumeration type. This parameter is used to specify the type of access required for the user data account store. TheUserDataAccountStoreAccessTypeenumeration consists of two members:


    • AllAccountsReadOnlyRead-only access to the application and user data accounts of the system
    • AppAccountsReadWriteRead/write access to the current app's user data store


The enumeration shows that although we can retrieve the user data account outside the current app itself, there is no write permission for the user data account other than itself.



Here we select the first type of access, using the following code to request the user Data account storage area:


await Userdataaccountmanager.requeststoreasync (userdataaccountstoreaccesstype.allaccountsreadonly);  


Gets the user data account storage instance of theUserDataAccountStoretype, which contains three methods:


    • Createaccountasync Create a user data account.
    • Findaccountsasync returns the collection of accounts in the user data account store based on the specified access type.
    • Getaccountasync gets the specified user data account.


Here we call toFindAccountsAsyncget all the user data accounts and do the next step. See the sample code on Github for a specific demonstration.


Get System User Information


In Windows 8 apps, we useWindows.System.UserProfileUserInformation in the namespace to access the user account information that the system is logged on to. In Windows 10 and later versions of Windows, itUserInformationis no longer supported. Because in Windows 10, apps cannot get user information unless they are authorized by the user. Windows 8 apps are, by default, licensed. Also, the old Windows 8 app runs on Windows 10 o'clock and does not get user information properly.



On Windows 10 We need to get user information using the Windows.System.User type provided by the new API. Note Using this API requires the app to configure the user account information feature in the manifest file.



UserThe class provides three static methods and their overloads:


    • Createwatcher creates a monitor that is used to set up events when enumerating user accounts or changing user accounts.
    • Findallasync Find all user accounts.
    • Findallasync (usertype) finds the user account of the specified type.
    • Findallasync (Usertype,userauthenticationstatus) finds the user account for the specified type and validation status.
    • Getfromid gets the specified user account instance based on the ID.


We canFindAllAsyncGetFromIdget the user account instance through or method, after getting the user, can obtain the user's property information by calling the Getpropertyasync method. GetPropertyAsyncthe Knownuserproperties method takes a parameter of type string, and the specific incoming content can be obtained through the properties defined in the class. TheKnownUserPropertiesknown available user account property key name is defined in the class. For example, when we want to get the account display name, we can use the following methods:


string await user. Getpropertyasync (Knownuserproperties.displayname);  


UserThe class also contains the following three attribute members:


    • Authenticationstatus gets the validation status of the user account. The return value is enumeration type Userauthenticationstatus.
    • Nonroamableid gets the user's non-roaming ID.
    • The type gets the user account types for the user. The return value is enumeration type Usertype.


With the use of Userdataaccount and user two APIs, the application can better implement unique user identification, user account system, custom authorization and other features.






For more information, see the following updates to this article.



Second: UWP apps get all kinds of systems, user information (2)-Store authorization information, retail demo mode information, ad ID, EAS device information, hardware identification information, mobile network information



Read Address: http://validvoid.net/uwp-system-info-collect-2/






UWP apps get all kinds of systems, user information (1)-basic information about devices and systems, app package information, user data account information, and user account information


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.