cancel
Showing results for 
Search instead for 
Did you mean: 
WarrenBelz

Detecting mobile device app operation

There is a generally simple method of detecting a mobile device where

Location.Altitude > 0 || Acceleration.X > 0

being true will detect a mobile device (as opposed to a PC), but we now have "cross-over" devices with these sensors being used as office PCs - so how do we detect them?
What we really need to know is if the app is being run in a browser or on the Mobile App.
One method I have tested which works is this - try to save a file with SaveData - at App OnStart, run this

Set(
   gblDevice,
   If(
      IsError(
         SaveData(
            Table(
               {Value: 1},
               {Value: 2}
            ),
            "MyTest"
         )
      ),
      "Desktop",
      "Mobile"
   )
)

and then test gblDevice for the value.
NOTE: This will only work properly on a PC / browser if this setting is switched off in the App.

 

WarrenBelz_0-1670727721281.png

Comments

Does this work for apps created in the Power Apps for Teams Studio?

Doesn't seem to be working anymore as it flags a runtime error and IsError only seems to look for formula errors...

Found a workaround -- use Acceleration.X instead and enable named formulas

 

Create a named formula set to IsBlank(Acceleration.X)

 

If this is true, then the app is running on desktop. If this is false, then the app is on mobile. You can use string interpolation to output a string based on this Boolean value.

 

The issue with using this in OnStart is that OnStart is not real-time and runs before Acceleration (and similarly, Location) is initialised. By using named formulas, it updates in real-time and will not suffer from this race condition

 

Desktop devices including laptops are unlikely to have gyroscopes since they're typically stationary when in use, and so won't produce any Acceleration values. Gyroscopes are standard in mobile devices including tablets, and so will produce these values.