Is there a correct / recommended way to detect my UWP application that I run on the phone?

Trying to use universal Windows applications with JavaScript I noticed that the WinJS.Utilities.isPhone property WinJS.Utilities.isPhone no longer available, which makes sense, since there would be no reason to ask for it at runtime.

I want to know only for testing purposes, if there is a correct way to detect the device on which my application is running.

EDIT: My question is NOT about detecting a mobile browser. I'm talking about a completely new universal Windows application for Window 10 that can run on phones, desktops, tablets, Xbox, HoloLEns, IoT devices, etc. WinJS had a property that would tell me if I was on the phone or not. This property has already disappeared. Please do not close this question due to duplication with "mobile browser detection". This is NOT what I need.

+8
javascript winjs win-universal-app
source share
3 answers

Warning. Any form of device discovery is fragile due to the dynamic nature of the hardware - a new device may arrive tomorrow, which will violate your application logic. It is best to use these APIs only for telemetry / analytics, and not for running runtime behavior.

Most often, what you really want to know is some attribute of a device or application that is not associated with a device family (does this device support the SystemTray API? Is there a keyboard there? Is this a window with a width of more than 500 pixels? Etc.).

However, in Windows 10, you can request DeviceFamily through AnalyticsInfo.VersionInfo.DeviceFamily , and it will tell you things like Mobile or Desktop or Xbox, etc. (Where "Mobile" can be any class of devices - phone, tablet, etc.). There is also a DeviceForm property that can be useful, but again you cannot really rely on it at runtime to deterministically say that you are working on a “phone”.

Thus, the main answer is that "you can use these APIs for telemetry, but don’t enter any values ​​in your application so that it does not break when a new device arrives on the market." At the very least, always make sure you handle the case where the return value is not what you know about a priori.

+11
source share

You can also check the following links http://www.abeautifulsite.net/detecting-mobile-devices-with-javascript/ http://www.sitepoint.com/detect-mobile-devices-jquery/

and of course a similar post here on stackoverflow with a good answer

Mobile browser discovery

And speaking of Windows 10, extracting from a Winjs Github replica, here is the answer.

https://github.com/winjs/winjs/issues/601#issuecomment-87137485

Answer from Github WinJS repo

+1
source share

There are many JS libraries to determine which platform / device is being used.

I personally love to use this lib: https://github.com/kaimallea/isMobile

Then you can detect the mobile device this way:

 isMobile.apple.tablet isMobile.android.phone 

etc.

If you have an idea to implement such an identity yourself, keep in mind that it makes some efforts to keep it up to date, since the methods for detecting a mobile device may change over time.

In general, a common way to discover a user device is to check request headers.

Keep in mind that you cannot completely rely on this information - the headers can be easily changed. Google for User Agent for more information.

Thus, “abandoning the authorization process for users with phones” is a very bad idea

0
source share

All Articles