Tell an ODKCollect user if they are online or offline

Hello team,
I would like to insert a hyperlink in a form and display it only if the device is connected to internet (ODK Collect).
A calculation with some thing like

if(${network_state} = "online","You are online.","You are offline.")

Is any widget can achieve that? I can't find anything like.
Thanks for you support.

There is not a way to do exactly that inside Collect. I think it might require additional app permissions from the Android system. As a workaround, you could have a "yes/no" question that asks something like "Do have Wi-Fi or cellular data for internet browsing available right now?" and then show the link only if they answer "yes".

1 Like

Hi @muzele ! :waving_hand:

Does this look like what you had in mind?

Demonstration:
NetworkTest

Note: In the demonstration above, I filled in two different submissions - one in presence of an active internet connection (it showed a URL to visit in the form), and one without internet connectivity (it showed a "no internet connection" message in the form).

Let me know what you think. Have a great day! :smile:

Hello Dan,
Thanks for your answer, but this way of doing things forces the user to confirm whether he's online or not. The problem is that his answer could be wrong. The aim is to calculate automatically without user intervention.
Thanks

Hello Minimal,
This is exactly what I want to do.
How did you achieve that? may you please share the process?
Thanks :wink:

Hey @muzele ! :waving_hand:

In general, I'd suggest following the workflow shared by @danbjoseph - that should be the first preference, as it's much simpler and more straightforward.

Though, here's how I implemented it on my end:

As @danbjoseph pointed out, there isn't a built-in feature in ODK Collect to achieve this directly. However, ODK Collect does support working with other external apps on the Android device via intents. So, there are two different apps involved here:

  1. App 1 - ODK Collect:

    • The main data collection app.
  2. App 2 - ODK Network Checker:

    • A small app I built myself.
    • It checks whether the device has a mean for an active internet connection and returns the result to ODK Collect when triggered.

Workflow:

When the "Launch" button is tapped in the form (within ODK Collect) - as showcased in the demo, it triggers the ODK Network Checker app in the background. That app checks for the mean for an internet connectivity and returns the result to ODK Collect, which I then used to control form logic (relevance conditions, etc.).

P.S. I didn't share the form or APK here because I wasn’t sure if sharing custom-built / random APKs is allowed on the forum ( @LN , @yanokwa - can we? :sweat_smile: :grimacing: ).

Hope this helps! Wishing you a great day! :smile:

Random APKs are allowed, but in general, it's not a good idea to install random APKs!

@muzele Why do you want to know if someone is online or not as part of the form filling process? What high-level problem does it solve?

2 Likes

Hello @Yanokwa,
Thanks for you feedback.
The objective is very basic but can save a lot of time. Users are conducting surveys from multiple locations (connected or not). If the user is online, he or she will have access (from the form) to related resources stored on the cloud. For example, images, documents, etc. All this data can't be stored in the form. Making links to these resources available when the user is not online will waste a lot of time during the survey, as they will tend to open the links.
Asking the user to confirm manually may be inaccurate and/or unreliable. Users may provide incorrect information or may think they are connected.
Thanks,

1 Like

Hello Minimal,
Hope you're doing fine today !
Possible to share your XLS and APK ?
If you have your APK source share on a git directory, it would be great, so I can customize.
Thanks,

Thank you so much, @yanokwa ! :smile:

@muzele - apologies for the delayed response, I was caught up with a few deadlines. You may find the source code, APK, and a sample form here .. !

Have a great day! :smile:

Hello Minimal,
Many thanks for sharing. Don't worry, I'll put it to good use. :wink:
Thanks and thanks again, I was stuck on a question in my form, but now everything is solved and I can still improve.
Have a great day! :smiley:

1 Like