cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5: What is the best Reliable way to detect on which device my app is running?

Former Member
0 Kudos

Hi,

I have developed a sapui5 app that can run on iPhone, iPad, and desktop. Depending on the running media, it will use different theme or UIs. The are several ways of detecting OS, device or screen resolutions, such as:

    navigator.userAgent.match(/(iPhone)/g)

    window.devicePixelRatio ==2

    scree.width()

    iQuery.device.is.phone

    $('#phone').css('display') == 'none'

My question: what is the best and Reliable way in the code to find out which of the following devices my app is running on:

   "iPhone" (valid for all kinds of resolutions)

   "iPad" (all possible types)

   "laptop/desktop"

Thanks.

Dong Zhu

Sr. Sys Developer●Enterprise Mobility●SAP●iOS●Web●Android

Accepted Solutions (1)

Accepted Solutions (1)

SandipAgarwalla
Active Contributor
0 Kudos

i think you should be using the Device apis, available under sap.ui.device

https://sapui5.hana.ondemand.com/sdk/#docs/api/symbols/sap.ui.Device.system.html

Former Member
0 Kudos

Hi Sandip,

Thanks for the quick reply. My major concern is how accurate this api will be. The followings are my use cases:

"Launch mode":

     If my app is launched (eg on iPhone or iPad) as a standalone app or via a url, would this api be accurate enough?

"Device types":

    "Phone": can this be always detected for variant devices such as iPhones(with different resolutions, 4S, 5S etc), or Android phones, Windows Phones? How would this api work if a new type of mobile phone is released?

Any comments? Thanks.

SandipAgarwalla
Active Contributor
0 Kudos

Hi Dong

Well, I havent tested this on diff OS so cant really comment on the reliability ..my guess is they should be working in most cases, else we have OSS..

If new types of mobile/OS are introduced - I am sure SAP UI5 team will add the support.

for the OS and the version - you may have to use a combination of the apis

sap.ui.Device.OS.version   /   sap.ui.Device.ios

hope this helps.

Sandip

AndreasKunz
Advisor
Advisor
0 Kudos

Hi,

the sole purpose of this Device API is the detection of different device/platform characteristics, so it should be reliable or will be fixed in case it is not.

Just be sure to understand the detection it does. E.g. for Android phones and tablets: where is the border? Is a Galaxy Note a phone or a tablet? Or the Microsoft Surface tablets, are they really tablets - they can have a keyboard - or are they laptops (="desktop")? So the decision is not always clear, but the API has its defined behavior for these edge cases.

For iPhone/iPad the decision is very clear, though.

Standalone detection is not part of the API.

Regards

Andreas

Former Member
0 Kudos

Hi Sandip and Andreas,

Thanks for your comments. The deatils below works fine so far. Br, /Dong

jQuery.device.is.android_phone

jQuery.device.is.android_tablet

jQuery.device.is.desktop

jQuery.device.is.ipad

jQuery.device.is.iphone

jQuery.device.is.landscape

jQuery.device.is.phone

jQuery.device.is.portrait

jQuery.device.is.standalone

jQuery.device.is.tablet

Answers (0)