Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« Mega Open Day | Main | Some Windows Phones Contain NASA Chips »
Saturday
Apr022011

Find out if you are using the Windows Phone Emulator

It is often useful in a Windows Phone program for the code to know whether or not it is running on a real device.  It is actually easy to do this:

  1. Add Microsoft.Phone to the references to your project if it is not already there.
  2. Put the following line at the top of your program.
    using Microsoft.Devices;
  3. You can now write code like this:
    if (Microsoft.Devices.Environment.DeviceType ==
                                                                               DeviceType.Device)
    {
        // we are running on the real phone
    }

You can use DeviceType.Emulator in the test to see if you are running on the emulator.

Reader Comments (4)

I imagine this is something you would eventually remove when it came to releasing an app?
April 2, 2011 | Unregistered CommenterCameron Wilby
is there any way to use this further, say for instance to find out which phone specifically you are using?

i wouldnt mind expanding the control scheme for hardware keyboard devices (venue pro) and / or applying dithering filters to AMOLED screen phones (omnia 7)...

would be a nice touch to improve support on specific hardware
April 2, 2011 | Unregistered Commentermechacrash
Cameron: You can actually leave the tests in production code if you like, as long as they don't slow the program down too much or make it too large. If they do you can use conditional compilation to completely omit lines of test code.

Mechacrash: I believe there are some device properties in the registry that you can use to find out the hardware version. However, I'm not mad keen on this kind of thing. The idea is that Windows Phone is a unified platform and all programs will work in the same way on all devices. I think if you made a program that worked in a markedly different way on each platform you might encounter problems with certification.
April 4, 2011 | Registered CommenterRob
wow... thats a pain.

the hardware keys available on slider phones werent my main objective, mostly the applied dithering. When i played with the omnia 7 gradients just got ruined.

Ive been told its also because applications cant take advantage of 24bit colouring, but i have no inside proof either way of that :/

thanks for the info anyway, ill try and contact their support regarding it if need be
April 4, 2011 | Unregistered Commentermechacrash

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.