Running on Windows Phone 7 Emulator or real Device

November 17, 2010

In one of the labs I’m writing for the Windows Phone Training Kit I’m using kind of GPS Emulator for simulating a geographic location (Latitude, Longitude). This simulator comes in handy when writing location aware application, and you don’t really have a GPS on the emulator. So instead of using C# pragmas for picking the correct path, knowing whether the application is running on a real device or not, there is an easy static property for checking that:

if (Microsoft.Devices.Environment.DeviceType ==
    Microsoft.Devices.DeviceType.Emulator)
{
   
MessageBox.Show("Running on Emulator"
);
}

else
{
   
MessageBox.Show("Running on Device");
}

Opening Microsoft.Phone.dll using reflector is seams like the:

Microsoft.Devices.Environment.DeviceType is always DeviceType.Emulator.

image

Yea, that is suspicious. It looks like the phone device itself has different assemblies.

But this works fine on my WP7 device.

Enjoy using the Emulator, but don’t forget to test your application on a real device…

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*