How to recognize the OS of a mobile device?

0
Hi guys,   We have a mobile application running on Mx. I want to trigger OS specific functions, and therefore I need to know whether an user is iOS user or an Android user. How could I determine in Mx which type OS the mobile user has?   thnx
asked
3 answers
8

You could retrieve this information in a Java action using ISession.getUserAgent().

This results in a string looking like this: User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko

answered
3

Hi Enzo,

 

I think there are different ways to do this (custom java action / JavaScript / JQuery). I have not tried it or read it fully but just found this which I thought might be helpful to you http://stackoverflow.com/questions/21741841/detecting-ios-android-operating-system

Hope this helps!

 

Cheers,

Mohammed Siddiqui 

 

answered
0

You can use JavaScript window.matchMedia() method to detect a mobile device based on the CSS media query.

if (window.matchMedia("(max-width: 767px)").matches)
{
  // The viewport is less than 768 pixels wide
  document.write("This is a mobile device.");
}

You may also use navigator.userAgentData.mobile .

const isMobile = navigator.userAgentData.mobile;

Another approach would be a responsive media query. You could presume that a mobile phone has a screen size greater than x and less than y. For example:

@media only screen and (min-width: 320px) and (max-width: 600px) {}

answered