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

  • I understand now, is there a good way to display, for example, the N/A icon on the watch when a web request is not met?

  • I understand now, is there a good way to display, for example, the N/A icon on the watch when a web request is not met?

    Look at the code at the end of https://forums.garmin.com/developer/connect-iq/f/discussion/406872/how-to-make-an-alert-when-mobile-data-is-not-available/1913424#1913424

    Change it as follows:

  • sorry but i want to import it here:

    lass Weather extends WatchUi.Drawable
    {

    function initialize()
    {

    Drawable.initialize({ :identifier => "Weather" });
    onSettingsChanged();
    }


    public function onSettingsChanged()
    {


    }

    public function draw(dc as Graphics.Dc) {

    not to WF.mc

  • Understand with a background service, it runs at most once every 5 minutes, and in that time, the connection could have been re-established, and consider that most of the time, onUpdate in a watch face only runs once a minute, and that window could be 6 minutes.

  • Yeah, it seems that there should be two completely separate indicators on the watchface:

    - bluetooth/phone icon: (constantly updated in onUpdate / onPartialUpdate): icon which indicates whether phoneConnected is true.

    For example, some watchfaces will show normal phone icon when phoneConnected is true, and a phone icon with slash ("no phone") when phoneConnected is false

    - weather data indicator: (updated when background data is available): if weather request is successful, show weather data. if weather request fails, show "--" or blank space.

    If you really want to, handle certain request errors differently (as discussed earlier). For example, if there is a certain error code that is returned when the phone does not have an internet connection, maybe you want to handle this code in a special way. (I probably wouldn't)

  • Yes, this is exactly the solution that would help me.

  • Unfortunately I have no experience with this solution, so would it be possible, since we already understood each other, to give me a code sample?

    You mean a sample for drawing an icon?

    One solution is to define a bitmap resource and draw it in your app.

    Search for "bitmap" on this page:

    [https://developer.garmin.com/connect-iq/core-topics/resources//#bitmaps]

  • I can draw icons, but what I can't figure out yet is how to make code that will take into account the error in the weather.

    I have to try and figure out how to do it.

    And the problem is what jim_m_58 :

    Understand with a background service, it runs at most once every 5 minutes, and in that time, the connection could have been re-established, and consider that most of the time, onUpdate in a watch face only runs once a minute, and that window could be 6 minutes.

  • I can draw icons, but what I can't figure out yet is how to make code that will take into account the error in the weather.

    I have to try and figure out how to do it.

    Examples have already been posted in the thread, I'm not sure what more you need.

    forums.garmin.com/.../1913508

    https://forums.garmin.com/developer/connect-iq/f/discussion/406872/how-to-make-an-alert-when-mobile-data-is-not-available/1913424#1913424

    The outline of the solution is:

    - In the background process, get responseCode from onReceive, and return it to the foreground, along with data (OWM data)

    - In the foreground process, check responseCode. If responseCode is not 200, that indicates an error. Now it's your choice what to do with the error.

    If you need additional help, you will need to be more specific about exactly what you can't figure out.

    sorry but i want to import it here:

    lass Weather extends WatchUi.Drawable
    {

    function initialize()
    {

    Drawable.initialize({ :identifier => "Weather" });
    onSettingsChanged();
    }


    public function onSettingsChanged()
    {


    }

    public function draw(dc as Graphics.Dc) {

    not to WF.mc

    I hope you will understand when I say that I don't know how to help you here because:

    - I don't know why I need to know this to help you with your problem

    - I can't see the rest of your code

    - I don't know what WF.mc is or does

    - I don't know exactly what draw() does (as opposed to onUpdate() in your view). Does it handle all the drawing logic? Some of it? Why should it change the solution?

    Again I can guess some of these things, but I already guessed things incorrectly at the beginning of the thread.

  • I meant that I have a file WeatherDrawable.mc, which is in layout.xml

    so it is:

    class Weather extends WatchUi.Drawable
    {

    function initialize()
    {

    Drawable.initialize({ :identifier => "Weather" });
    onSettingsChanged();
    }

    in this file I have all the weather data and I want to do the connection check there.

    file WF.mc is WF_View.mc.

    class WF_View extends WatchUi.WatchFace
    {