天天看点

Device information in Windows 8 store apps

Our Sticker Tales game tracks var­i­ous activ­i­ties via Google Ana­lyt­ics using code that grew into our CSharp­An­a­lyt­ics open source project.

But we also want to add some sys­tem met­rics that could help us answer other questions:

When is it time to exploit fea­tures of an OS update?

Do peo­ple on tablets play longer than peo­ple on laptops?

How long do var­i­ous timed activ­i­ties take by CPU?

Does not hav­ing a phys­i­cal key­board affect pur­chase flow completion?

To do this we want to record:

Proces­sor architecture

Device man­u­fac­turer, model and form fac­tor (category)

Win­dows ver­sion number

On Win­dows Phone and .NET this infor­ma­tion is eas­ily avail­able but in Win­dows Store apps it is not. Microsoft have made this dif­fi­cult because your appli­ca­tion should not change it’s behav­ior based on this infor­ma­tion.

The fol­low­ing code uses the PnPOb­ject API to best-guess these things. It is not bullet-proof and could eas­ily fail on machines with cus­tom HAL dri­vers (I haven’t seen one of those in years) or on other lan­guage edi­tions of Win­dows (not yet tried).

It is good enough in my opin­ion for ana­lyt­ics, log­ging or trou­bleshoot­ing and for noth­ing more.

To use it simply:

var windowsVersion = await SystemInfoEstimate.GetWindowsVersionAsync();

var processor = await SystemInfoEstimate.GetProcessorArchitectureAsync();

继续阅读