Make a "link" from my commcare app into a website OR different app?

Question about making a link from the commcare app inside our phone... to another program:

Very normal: I have an ecascade app that collects lots of variables in a form.

Let’s imagine that a scientist in my company did some research on my data, and he made a machine learning algorithm that was able to make a cool, valuable prediction based on just 6 variables. And imagine, in a form in my commcare app, I do have the 6 numbers that are needed for that prediction... they are sitting nicely in hidden variables.

That scientist is able to make a program in R language... and that program would simply take the 6 variables and generate output of the prediction that results. [Note: No, it is not possible to express the relationship as a simple formula... It has to be a full R program.]

What if my normal Commcare form, running in a phone, does actually have those 6 separate values. Could the form running on the phone create some kind of link / automatic call / API call to EITHER another app (either an android app on the very same phone, OR a web app that’s available on the net)? Is that hard to do?

ACTUALLY I am thinking just as I am writing this, and I am realizing one possible way to do that could be:

  • The R application could be running on a web app,
  • That web app URL could be set up with a query string with 6 parameters... so that the 6 variables could be sent to the program right in the URL, similar to this: www.myapp.org/?a=124&b=6&c=100&d=98&e=0&f=12
  • If you don’t’ see red flags with the above, then the viability of this method would come down to a simple question: If I use string commands in the commcare form to assemble that complete URL correctly, then can I make a question in a commcare form that will display, in a label item in the commcare app, a clickable link that takes the user to that exact URL, and if clicked, it will launch the web browser in that phone and navigate there?

THANKS!

Eric

Hi Eric,

It may be possible to construct a complex URL which permits this, but wanted to flag that you can also create Custom Intent Callouts which will let you control granular behavior for on-device jumps.

If you haven't read about this option it's worth considering whether it's a good fit for your use case.

-Clayton

*** here's another reply I got from Latt Levasseur over email ***

  • What if my normal Commcare form, running in a phone, does actually have those 6 separate values. Could the form running on the phone create some kind of link / automatic call / API call to EITHER another app (either an android app on the very same phone, OR a web app that’s available on the net)? Is that hard to do?**

We do have a question type in the CommCare form builder, under the advanced section, called "Android App Callout." It lets you specify some parameters in the form (such as your 6 values) and basically send those over to the other app. CommCare then waits for the other app to finish its work, and you can arrange for it to send a package back - say, the output of the algorithm, that you want to populate a hidden value with.

There's a confluence for it here: https://confluence.dimagi.com/display/commcarepublic/Integrating+Android+applications+with+CommCare

Some amount of Android programming knowledge is required- the external application, of course, must be configured correctly as must the CommCare form in question. As mentioned in the above link, in my experience it was important for the programmer of the external app to understand Android's "intents" system. When the new app is installed, Android needs to have it registered in the right way, such as to make it callable to CommCare, and to allow CommCare to receive data from it (which is then an API configuration/mapping question.)

A web app would work differently. You can put a hyperlink into a question label in a form, as you can see in the table here: Text Formatting - CommCare Public - CommCare Public

The problem with this would be getting your output back into CommCare from the web app, which I don't believe we have a function for. Depending on what the output is, you could ask the user to copy/paste something from the web app?

  • If you don’t’ see red flags with the above, then the viability of this method would come down to a simple question: If I used string commands in the commcare form to assemble that complete URL correctly, then can I make a question in a commcare form that will display, in a label item in the commcare app, a clickable link that takes the user to that exact URL, and if clicked, it will launch the web browser in that phone and navigate there?

Yes you can make a clickable link, and yes you can format the link dynamically in your form.

thanks much! appreciate it

Yes, it is possible to create a clickable link in your Commcare form that, when clicked, opens a web browser on the phone and navigates to a URL with the 6 parameters. Here's how you can approach it:

  1. In your Commcare form, use string commands to dynamically assemble the complete URL with the 6 parameters.
  2. Add a label item to your Commcare form where you want to display the URL.
  3. Use Commcare's display logic or formatting options to make the URL text interactive and guide the user to open the web browser on their phone and navigate to the assembled URL. This can be achieved using HTML-like formatting.

When the user interacts with this element in your Commcare form, it should open the web browser on the phone and navigate to the URL you've assembled with the 6 parameters. The web app running on that URL can then process these parameters as needed.

This method should work for launching the web app and passing the parameters to it. Just ensure the URL assembly and formatting are done correctly within the Commcare form.

in theory yes

try this out in your question or label label

[Hyperlink Text label](Path to website with parameters)