Check GPS enabled or turn it on / monkey-c

Hi,
is there a method to check, if the user has the GPS enable, or do it for him?
btw: ist there a list of all Sys.getDeviceSettings methods?

thanks
Sven
  • In a watch-app or a widget, GPS will be off unless the code turns it on. Watch faces can't turn it on, and DF's it's on or off based on the settings for that activity, and you can see if it's on or off based on the data you see in Activity.Info.

    in a watch-app or widget, you do a call like

    Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));

    to turn it on

    On watches like the va, even if GPS is switched off, if an app needs GPS, it turns it on with the call above.
  • Thanks to point this out for me.
  • Former Member
    Former Member over 8 years ago
    How do you check whether GPS is ready?

    I've been trying to get this work on a VivoActive using the current SDK 2.1.3.

    If GPS is not ready my watch just crashes with the connect iQ logo and there is a not very useful message about failing to invoke a symbol, but there is no line number reference in the CIQ_LOG.

    The simulator seems happy and if I launch another app with GPS or wait for my watch to lock on the app works on my watch.

    I've tried things like setting a global variable called posinfo in the callback function and null checking it, but I still get the crash. I declared posinfo and apprun at a top level so that it can be used in my views and other code. Here is the on start and stop in the entry point:

    // onStart() is called on application start up
    function onStart(state) {
    apprun = App.getApp();
    Posn.enableLocationEvents(Posn.LOCATION_CONTINUOUS, method(:onPositionUpdate));


    }

    // onStop() is called when your application is exiting
    function onStop(state) {
    nightscoutCycleView.stopRecording();
    Posn.enableLocationEvents(Posn.LOCATION_DISABLE, method(:onPositionUpdate));

    }

    function onPositionUpdate(info) {
    posinfo = info;
    //sys.println(info.accuracy);
    }

    Or is the problem when I try to get information from the currentActivity?

    R.
  • I do usually do it in onPosition() by checking the quality, but it will also work with Activity.info and checking the quality there

    In my case, I use onPosition() as I don't start recording the activity until after I've gotten good GPS data.
  • Former Member
    Former Member over 8 years ago
    Thanks for the tip

    Hi Jim, thanks for the tip on this.

    I made two changes both null checking. First in onPosition but I don't think this fixed it.

    function onPositionUpdate(info) {
    if (info.accuracy != Posn.QUALITY_NOT_AVAILABLE){
    posinfo = info;
    }

    I think that the real problem was that I needed to null check the currentSpeed in my activity thus:

    if (currAct.currentSpeed != null) {
    currspeed = currAct.currentSpeed;
    }
    else {

    currspeed = 12000; // unambiguously wrong for debugging only

    }

    It seems that the simulator doesn't mind nulls and casts it as 0, but the Vivoactive goes belly up with insufficient info to debug it. An alternative reality is that I couldn't find how to turn GPS off in the simulator, and other devs need to be aware of testing this kind of behaviour.


    Replying to provide an answer to anyone who find this and to say: Thanks, jim_m..., I really appreciate you replying to my cross post.

    R.

    I do usually do it in onPosition() by checking the quality, but it will also work with Activity.info and checking the quality there

    In my case, I use onPosition() as I don't start recording the activity until after I've gotten good GPS data.
  • I think that the real problem was that I needed to null check the currentSpeed in my activity thus:


    It's a good practice to check everything in Activity.info for a null before you use it. This is a case when the the sim, you don't see the nulls at the same time as on a watch, as you're playing back/simulating a .fit so data can get filled in before recording starts.