How to make an alert when mobile data is not available?

Hello.

Is there a way to make a short message on the watch when I turn off the connection (mobile data)?

I'm using OWM data, currently I'm using

if (!System.getDeviceSettings().phoneConnected) , but this only solves the problem with BLE.

I still need to solve

var Settings = System.getDeviceSettings();

if (Settings has : connectionAvailable) {.

Or if there is a better way, for example Communications.makeWebRequest?

Then please give an example of how to solve this problem.

Thank you

  • No, I definitely don't want you to write my code for me.

    as I mentioned, I currently only have BLE control and when Bluetooth is disconnected from the watch, I immediately see an error message in the weather area and the N/A icon, but the weather data is deleted and only when the watch connects to Bluetooth again does the weather data load again.

    I have no problem posting my code samples here, but the problem is that when I insert the insert - code function, my code cannot be displayed on the forum and so I am forced to only send SCR.

    The original idea and extension of my existing code was to also monitor the connection and generate an error message just like in the case of Bluetooth.

    I apologize if it looks confusing but I don't have much opportunity in the internal editorial system to publish code samples and be more specific.

    I was only interested in some sample design and I would have somehow modified my code according to your suggestion and understood it, and most importantly, I found logic in it.

     var connected = true;
           var Settings = System.getDeviceSettings();
           if (Settings has : connectionAvailable) {
           connected = Settings.connectionAvailable;
        }
        if ((!connected)) {
            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
            dc.drawText(128, 22, Graphics.FONT_XTINY, "connect to garmin app", 1);
            dc.drawText(51, 49, $.Font_Weather, Set._NA_, 1);
        } else
         {      
        var Wdata = drawWeather(dc);

  • Welcome to the forum. About not being able to post code you can write here: https://forums.garmin.com/developer/connect-iq/f/forum-about-the-forum maybe when we reach 100 developers who can't post code Garmin will fix it...

  • I have no problem posting my code samples here, but the problem is that when I insert the insert - code function, my code cannot be displayed on the forum and so I am forced to only send SCR.

    Yeah the forum is super annoying like that. Sometimes it helps to split a long comment into multiple comments.

    Sorry for the criticism, it is just difficult to help without knowing certain details.

     var connected = true;
           var Settings = System.getDeviceSettings();
           if (Settings has : connectionAvailable) {
           connected = Settings.connectionAvailable;
        }
        if ((!connected)) {
            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
            dc.drawText(128, 22, Graphics.FONT_XTINY, "connect to garmin app", 1);
            dc.drawText(51, 49, $.Font_Weather, Set._NA_, 1);
        } else
         {      
        var Wdata = drawWeather(dc);

    [1/3]

  • ^ This looks ok to me, except that if you want to support very old devices (with CIQ 2), you should have fallback code if connectionAvailable is not present. (This would be good practice in any case, unless you are either 100% sure connectionAvailable will be present and/or you are tight on memory and cannot waste the code.)

    var connected = false;
    var settings = System.getDeviceSettings();
    if (settings has :connectionAvailable) {
        connected = settings.connectionAvailable;
    } else {
        connected = settings.phoneConnected;
    }

    [2/3]

  • I will say that a message like this could be seen as obtrusive unless displaying weather is crucial feature of your app and/or the user has opted in to display weather (and it's a crucial feature for them).

    Personally if I go for a run without my phone, or if I just disable bluetooth, I may not want to see a message like "connect to garmin app" on my watchface all the time.

    Another solution could be to display a phone or wi-fi icon with a slash through it, to indicate "no network connection". (Ofc it in some cases it really means no connection to Garmin Connect app...)

    Since you've already implemented the connection check this way, perhaps it isn't important to *also* specifically check for a failure in makeWebRequest *due to unavailable connection*. You may wish to somehow indicate the makeWebRequest failed (maybe with an error icon?) Or you could just display an empty space or "--" where the weather data would normally go.

    [3/3]

  • What I do (at least as an option) for OWM and other sites, is I will not only display temperature, but the time from the last good request.  If you are requesting data every few minutes, it's not a huge deal if you miss one when you away from your phone for a few minutes, but if it's a much longer time, it might be a warning.

    My phone is often sitting on my desk, and I can lose connection if I grab a coffee from the kitchen (the microwave can mess up ble).  That's not something I really want to be alerted about...

  • var connected = false;
    var settings = System.getDeviceSettings();
    if (settings has :connectionAvailable) {
        connected = settings.connectionAvailable;
    } else {
        connected = settings.phoneConnection;
    }

    This solution is not working correctly for me.

  • I just wanted to be notified when the connection (mobile data on the watch) drops.

    As for the time of the last weather update, I also display it on WF.

  • This solution is not working correctly for me.

    Sorry, typo.

    I typed phoneConnection when I should've typed phoneConnected

  • I figured that out, but it still doesn't work for me and the error message keeps appearing and it interferes with the weather area.