Canvas Apps Expressions Responsiveness UI

Know if a user is using Desktop or Mobile

Desktop Or Mobile?
Desktop Or Mobile?

Introduction - Mobile or Desktop?

In spite of being in the middle of my responsive app series, I came up with this quick tip. Like many of my blogs, someone asked this in our team chat at Hitachi Solutions. Question? How to find if a user is accessing the app on desktop or mobile device?. This can be useful for several reasons e.g. to create a mobile only layout, to expose certain functionality on desktop etc.

The approach

Traditionally, I used this:

Location.Altitude > 0 && Acceleration.X > 0

The difficulty with this is that some laptops have accelerometers and GPS.

The alternative approach is to check for one of these two (or both) parameters using the Param function (to learn more about the function, click here):

If(
    IsBlank(Param("source")),
    "device = mobile",
    "device = desktop"
)

OR

If(
    IsBlank(Param("tenantId")),
    "device = mobile",
    "device = desktop"
)

Here is how an app with two labels with their Text properties set to the above expressions looks on desktop:

An app on desktop
An app on desktop

And here is how the same app looks on a mobile device:

The same app on mobile
The same app on mobile

Conclusion

To figure out if users are using mobile devices or desktop, you can simply check for source or tenantId parameters. If they are not blank, the user is on a desktop.

Recent articles

  1. How to create responsive Power Apps!
  2. Responsiveness - the fundamentals!
  3. How to calculate the height of a flexible height gallery!

1 thought on “Know if a user is using Desktop or Mobile”

Leave a Reply