Get device information on Windows Phone 8.1 WinRT

Get device information on Windows Phone 8.1 WinRT

I see many interesting question on StackOverflow every day. One of those today was the question about determining if Windows Phone 8.1 app is running in the emulator. Here's one way you can get that information!

Finding out information about the device is useful in many ways, but one reason you might want that is definitely to know the difference between running on emulator and on a real device. Typical way of doing this on Windows Phone 8.0 was to use

Microsoft.Devices.Environment.DeviceType  

and this actually keeps on working on Windows Phone 8.1 Silverlight, so it won't break your app if you upgrade from WP8.0 to WP8.1. However, the question remains - how to do it on WP8.1 WinRT?

I remember that I was looking for a good way to find some sort of unique user ID in one of the last Windows 8.1 WinRT app I was working on, and then I found this class called Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation. EAS stands for Exchange ActiveSync. A bunch of questions remain on StackOverflow about the ID property of this class and whether and how is this property unique for a user/device. However, more importantly - the description of this class is

Provides the app the ability to retrieve device information from the local computer.

This sounds good enough to me to check whether the app is running on real device or emulator.
So, if you just create an instance of this object

EasClientDeviceInformation deviceInfo = new EasClientDeviceInformation();  

this is the info it gives you on emulators:

get device information on WinRT

However, if you run it on a real device, you get this information:

get Windows Phone 8.1 device information (real device)

I hid some information just in case.

So - many differences. But I like how on emulator you get "Virtual" as SystemProductName. So you could write a little helper class like this one:

public static class DeviceInfo  
{
    private static EasClientDeviceInformation deviceInfo = new EasClientDeviceInformation();

    public static bool IsRunningOnEmulator
    {
        get
        {
            return (deviceInfo.SystemProductName == "Virtual");
        } 
    }
}

And just use it like this:

if (DeviceInfo.IsRunningOnEmulator)  
{

}

What do you think? Do you know a better way? Leave your comment!

Igor Ralic

igor ralic

View Comments
Microsoft Certified Solutions Developer: Windows Store Apps in C#