locked
[UWP][C#] how can i detect on which device type[desktop,phone,tablet] is application running?

    Question

  • [UWP][C#] how can i detect on which device[phone,tablet,desktop] type is application running?
    Tuesday, September 1, 2015 3:42 PM

Answers

  • Why? What is the goal? There are different ways depending on what you're trying to do.

    For functionality it shouldn't matter. Check that the contract or function you need is present with the Windows.Foundation.Metadata.ApiInformation class (see the Guide to Universal Windows apps for more details) and then use it or not. In most cases you'll want to design for the screen size and format rather than for specific device. A small window on a desktop likely needs the same UI as a phone. A phone may be connected to a monitor and keyboard and need the same UI as the full desktop.

    For analytics take a look at the Windows.System.Profile.AnalyticsInfo class.

    Tuesday, September 1, 2015 4:01 PM
    Owner

All replies

  • Why? What is the goal? There are different ways depending on what you're trying to do.

    For functionality it shouldn't matter. Check that the contract or function you need is present with the Windows.Foundation.Metadata.ApiInformation class (see the Guide to Universal Windows apps for more details) and then use it or not. In most cases you'll want to design for the screen size and format rather than for specific device. A small window on a desktop likely needs the same UI as a phone. A phone may be connected to a monitor and keyboard and need the same UI as the full desktop.

    For analytics take a look at the Windows.System.Profile.AnalyticsInfo class.

    Tuesday, September 1, 2015 4:01 PM
    Owner
  • My goal is to develop an UWP application which will have multiple windows on desktop and tablet.

    Single window on phone, because on phone is window always maximized.

    I'm looking for best practice to detect this diference.

    Tuesday, September 1, 2015 5:56 PM
  • Why? What is the goal? There are different ways depending on what you're trying to do.

    For functionality it shouldn't matter. Check that the contract or function you need is present with the Windows.Foundation.Metadata.ApiInformation class (see the Guide to Universal Windows apps for more details) and then use it or not. In most cases you'll want to design for the screen size and format rather than for specific device. A small window on a desktop likely needs the same UI as a phone. A phone may be connected to a monitor and keyboard and need the same UI as the full desktop.

    For analytics take a look at the Windows.System.Profile.AnalyticsInfo class.


    My goal is to develop an UWP application which will have multiple windows on desktop and tablet.

    Single window on phone, because on phone is window always maximized.

    I'm looking for best practice to detect this diference.

    Thursday, September 3, 2015 6:27 AM
  • This is frustrating... Why there is so much arrogance in this "answer" and why it is even marked as answered? It does not answer the question! How does someone find which device family the app is running on? 

    As far as "Why? What is the goal?" goesthere are many reasons.

    One reason is to follow your own Microsoft advise and try to incorporate the Microsoft Advertising SDK into our Apps. This SDK requires different ad sizes (yes, different depending on the Device Family), however, it does not say how to do this. Here is a link: 

    https://blogs.windows.com/buildingapps/2015/10/08/new-advertising-features-and-walkthrough-of-using-microsoft-ads-and-mediation/

    And here is an excerpt:

    "If you create a UWP that will run across PC and Phone, your app will have to select the size of the ad SDK appropriate for the OS that is running the app."

    This is so frustrating... One Microsoft team (Advertising SDK) cannot even follow the design goals of Windows 10 and when people start looking for help they get greeted with such arrogant posts from another Microsoft team.  


    • Edited by dvmb Monday, November 16, 2015 5:30 AM formatting
    Monday, November 16, 2015 5:20 AM
  • Add to App.cs:

    public static bool IsMobile
    {
    	get
    	{
    		var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
    		return (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Mobile");
    	}
    }

    Friday, January 15, 2016 9:51 AM
  • Now THAT is how you answer someone's question...take note Microsoft; you're damn lucky there are mobile developers doing UWP to start with, don't piss us off.
    Friday, January 22, 2016 5:11 PM
  • "What is the goal?" is required information to answer the question properly.

    Naïvely checking the device family is the wrong answer more often than it's not and will end up with an app which works properly only in specific cases.

    As I mentioned, there are several different ways to determine what type of device the app is running on. Which will give the right information depends on what you need to do with that information. WolfSys's suggestion is basically a round-about way to do what I suggested for analytics. It won't give frantisekvoprsalek's scenario the right behavior, since it doesn't identify tablets, and it will break the app functionality in a continuum scenario (where "Single window on phone, because on phone is window always maximized" is not correct). There's no good reason not to implement multiple views on phone even if only one is visible at a time.

    Other scenarios will need other methods. For example, licensing for phone vs. tablet. vs. desktop is often done based on screen size.

    --Rob

    Friday, January 22, 2016 11:54 PM
    Owner
  • My aggressive response had to do with the fact that I landed on this thread because I was looking for a solution to a "specific case" having to do with how MediaCapture behaves differently across devices.  For that reason, I would propose that you take the approach of answer first, THEN advise (e.g. this is how you can do *this*, but before you do, you might consider *why* you are trying to do this.)  Although you were speaking to a specific question, UWP is new and there are a lot of developers looking for answers wherever they can find them (and Bing may land them here); so be verbose, share whatever you know.  We all have access to the "guidelines", but what we need are details at this point...
    Saturday, January 23, 2016 12:11 AM
  • Can't answer properly without knowing the question. I did answer for the two most common scenarios, but my crystal ball can only see so far.

    If you have a specific scenario you are interested I'd suggest opening a new thread with details of your scenario rather than complaining that an existing thread doesn't cover your scenario.

    Saturday, January 23, 2016 12:26 AM
    Owner
  • OMG man, you are so obtuse.  If you choose to reply to a question, it must contain an answer, simple as that.  Answer first, bloviate after.  wolfSYS was able to answer properly; he understood the question and supplied a clean and succinct answer...problem solved.  Learn from his example and stop talking.
    Saturday, January 23, 2016 12:48 AM