10
votes

I have an application for Windows Phone 7. I have created visual studio 2012 in windows 8 desktop. I am trying to use the application in Windows Phone 8 device also with some changes involved. How can I programmatically detect whether the device is Windows Phone 7 or Windows Phone 8?

4

4 Answers

10
votes

Just as you would on any other platform with C#: Environment.OSVersion

5
votes

You can use this toolkit to check the version of the phone: http://mangopollo.codeplex.com/

bool IsWP8() : Returns if the phone running the application is a Windows Phone 8

EDIT: If you don't want to use the whole toolkit here is how it checks it:

public static bool IsWP8 { get { return Environment.OSVersion.Version >= TargetedVersion; } }

    private static Version TargetedVersion = new Version(8, 0);

Creds to original author.

2
votes

You shouldn't need to.

Either it is a Windows Phone 7 app and will work on both Windows Phone 7 and Windows Phone 8 devices or it is a Windows Phone 8 application.

A Windows Phone 7 app running on Windows Phone 8 shouldn't be able to do anything that a Windows Phone 7 device shouldn't be able to do.

0
votes

This article has some good strategies as well.

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202996(v=vs.105).aspx

It is not just about run-time either, for example, your code may function one way on wp7 and another on wp8 depending on availability of an API. In this case a #define may the best way to go, because you really don't care what kind of device you are running on, but what SDK you were built against.