How to check if a Power apps canvas app is running on mobile or desktop device

Hello everyone and welcome to my blog. In today’s blog I will show how you can determine if your canvas app is running on a mobile or desktop device.

Many a times we need to check whether your Power Apps canvas apps is running on browser or on mobile device. If you search the internet, the most common solution you find is the below one.

Set(varIsMobile, Location.Altitude > 0 Or Acceleration.X > 0)

If Location.Altitude > 0 OR Accleration.X > 0 then you are running Power Apps on mobile device. And this is what even I implemented for my customer.

But to my surprise, we noticed that it is not working for all customers. Some of the reported problems were

  1. If I view the Power App in landscape mode, the device is treated as browser
  2. Some customers also had their laptops with accelerometers or GPS enable and when they were viewing the Power App from their laptop, the app detected the device as a mobile device.

While these are rare scenarios, I still needed to find a concrete solution for the customer. Wish Microsoft release some property of the App object like DeviceType or DeviceName or something on similar lines which shall make it easy to identify. But unfortunately there is no property at this point of time available in Power Apps to check the device on which the app is running.

I finally got an idea from this wonderful blog. From the maker portal screen, if you view the details of a Power App, you should see the web link of the Power App in the below format.

When you play an app in browser, you can look for these parameters in URL.

In the App OnStart, I used the below expression to determine the Device type based on these parameters in URL

Deployed the same and now it is working fine for the customer. Fingers crossed till they report something not working and I have some new learning again.

Hope this helped. You will also like the below posts.

Debajit Dutta