How to detect different devices?

Is there a way to detect the watch the app or WF is running on?
I get screen width and height and if they both 218 pixel size the device has round screen, if not it has square screen.
But how to detect whether it is Epix or Forerunner 920xt? I don't want to ask it to user but want to do it softly. :)
  • search the forum for how to use the resource.xml file.
    Or u can also find an example using the garmin supplied code for their golf-IQ app.
    Sorry for being brief. Typing on mobile.
  • This bit of code can be used to detect the device and a few device attributes...

    enum {
    DEVICE_FR920XT = 0x100001,
    DEVICE_VIVOACTIVE = 02000011,
    DEVICE_EPIX = 0x300011,
    DEVICE_FENIX3 = 0x010002,
    DEVICE_D2BRAVO = 0x010002,

    DEVICE_MODEL_MASK = 0xFF0000,

    SCREEN_SHAPE_RECTANGLE = 0x000001,
    SCREEN_SHAPE_ROUND = 0x000002,
    TOUCH_SCREEN_ENABLED = 0x000010,
    }

    function isDevice(mask) {
    return App.getApp().isDevice(mask);
    }

    function isTouchScreen() {
    return App.getApp().isTouchScreen();
    }

    function screenShape() {
    return App.getApp().screenShape();
    }

    class MyApp extends App.AppBase
    {
    hidden var _device;

    function initialize() {
    var devices = {
    "d2bravo" => DEVICE_D2BRAVO,
    "epix" => DEVICE_EPIX,
    "fenix3" => DEVICE_FENIX3,
    "fr920xt" => DEVICE_FR920XT,
    "vivoactive" => DEVICE_VIVOACTIVE
    };

    _device = devices.get(Ui.loadResource(Rez.Strings.Device));
    if (_device == null) {
    _device = 0;
    }
    }

    function isDevice(mask) {
    mask &= DEVICE_MODEL_MASK;
    return 0 != (_device & mask);
    }

    function isTouchScreen() {
    return 0 != (_device & TOUCH_SCREEN_ENABLED);
    }

    function screenShape() {
    if (_device & SCREEN_SHAPE_RECTANGLE) {
    return SCREEN_SHAPE_RECTANGLE;
    }
    else {
    return SCREEN_SHAPE_ROUND;
    }
    }
    }


    For it to work, you need to define a property in device specific resource files to describe the device that is being used. Something like this in resources-vivoactive/resources.xml would do the trick for the vivoactive...

    <resources>
    <strings>
    <string id="Device">vivoactive</string>
    </strings>
    </resources>


    Of course you'd need to keep the code and the resources up-to-date, but that shouldn't be too difficult.

    Once you have it in place, you can write code like this...

    var shape = screenShape();
    if (shape == SCREEN_SHAPE_RECTANGLE) {
    // ...
    }


    or this...

    if (isDevice(DEVICE_VIVOACTIVE | DEVICE_FENIX3)) {
    // on a vivoactive or fenix3
    }


    Travis
    [/code]

    Travis