Device ID in a UWP app (threshold 1)

倾然丶 夕夏残阳落幕 提交于 2019-12-05 00:09:46

问题


In Phone 8.1 you could get the device ID using HardwareIdentification, and even though the documentation says it exists for Desktop apps, it does not exist for a UWP app.

What is the alternative or a way to get a hardware ID for a UWP?


回答1:


You're running into a common issue when migrating an app from Windows (Phone) 8(.1) to the Windows Universal Platform.

The reason you're not seeing the HardwareIdentification is pretty simple: You don't reference the required sources!

You only see AnalyticsInfo and AnalyticsVersionInfo. This is because they are part of the Universal Device Family, as stated on the documentation page (https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.profile.analyticsinfo.aspx) at the very bottom.

The HardwareIdentification however is not part of the Universal Device Family, it's part of the Desktop and Mobile family, as Adriano alread stated in his comment.

To make the info available, you have to add the references to the specific extensions:

After that, make sure to check if the type exists, before calling it:

if (Windows.Foundation.Metadata.ApiInformation
    .IsTypePresent("Windows.System.Profile.HardwareIdentification"))


来源:https://stackoverflow.com/questions/32330759/device-id-in-a-uwp-app-threshold-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!