How do I determine if the platform is Windows or Windows Phone when running the Universal Windows app?

Asked 2 years ago, Updated 2 years ago, 91 views

その It's not an appropriate API, so I'll share the information.

When developing a universal Windows application for Windows 8.1 and Windows Phone 8.1, we would like to determine which platform is currently in use at runtime and separate the logic. Even if I look at MSDN, I can't find such an API.Is there a way to make it happen?

windows windows-store-apps

2022-09-30 10:39

3 Answers

Use the Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation class.The code below tells you whether the platform you are running is WindowsPhone or not (Windows):

As written in C#, the same API is available from C++, Visual Basic, and JavaScript.

bool DetectIfRunningOnWindowsPhone()
    {
        varinfo=new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
        return(info.OperatingSystem.Equals("WindowsPhone"))?true:false;
    }

See also http://msdn.microsoft.com/ja-jp/library/windows/apps/windows.security.exchangeactivesyncprovisioning.easclientdeviceinformation.aspx.


2022-09-30 10:39

In addition to EasyClientDeviceInformation, other simple methods include:

  • Get the name of the assembly that contains the App class by reflection (the creator should be able to distinguish!)

  • Determine by the Windows.ApplicationModel.Store.CurrentApp.LinkUri property (=URI of the web page of the store where the app is located)

Get the name of the assembly that contains the App class by reflection (the creator should be able to distinguish!)

Determine by Windows.ApplicationModel.Store.CurrentApp.LinkUri property (=URI of the web page of the store where the app is located)

@IT: WinRT/Metro TIPS: How do I separate logic between Windows and my phone?[Universal Windows Application Development]


2022-09-30 10:39

http://msdn.microsoft.com/ja-jp/library/windows/apps/dn609832.aspx#CrossPlatform

For Windows and Windows Phone projects, click Why don't you take advantage of the values defined as conditional compilation symbols?

public bool IsPhone = false;

# if WINDOWS_PHONE_APP
        IsPhone = true;
#endif

I don't use the API or anything, so I don't think it's good...


2022-09-30 10:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.