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:
And here is how the same app looks on a mobile device:
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.
What if we will embed the PowerApps in MS Teams? Will this work?