Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Excerpt

This page provides high-level guidance for how to integrate your CommCare application with other Android applications.

Multiexcerpt include macro
macro_uuid9078ada977a79df7-7c16a5d1-4fe44f8f-af1c828d-4ddd91c1ebe96c8d8a40e9b2
nameSoftware Plan - AdvancedPro
templateDataeJyLjgUAARUAuQ==
page[Internal] CommCare Public ManagementCommCare Help Site Design Guidance
addpanelfalse

Supported Application Integrations

Child pages (Children Display)
allChildrentrue

Android Application Integration Overview

CommCare offers a few options for integrating with external applications, including providing a Content Provider for accessing case and fixture data and Broadcasts for detecting events like syncs and submissions. However, Intent Callouts are the most common and robust option for integrating applications as part of the form entry workflow. The goal of such integrations is usually to have your custom external application appear as seamlessly as if it were a native question type, with resultant data ending up in the CommCare session such that this data is manipulable and submittable by CommCare.

...

  • Question ID: as usual

  • Intent ID: intent action for your activity - for example "android.intent.action.DIAL" to launch the phone dialer

  • Extra: keys and paths to form fields containing the values of arguments for the intent activity

    • The paths point to the location of this data - no hard-coding of values. The paths can point to hidden values that calculate the desired value

  • Response: any extra values for ODK to store, along with the paths of where to store them

...

Further, this question itself (test_app_callout) can also be set to a value as a result of the callout.

Expand
titleAdvanced (Update text / intent type)

CommCare additionally supports customizing the button text and setting intent type by editing the underlying XForm XML and setting the following attributes on the odkx:intent element:

  • button-label 

  • type

As an example, the following XML sets the intent type to "vnd.android-dir/mms-sms" and the button label to "Send SMS". 

AndroidManifest.xml
Code Block
languagexml
<odkx:intent xmlns:odkx="http://opendatakit.org/xforms" id="send_sms" class="android.intent.action.VIEW" button-label="Send SMS" type="vnd.android-dir/mms-sms">
	...
</odkx:intent>


...

For the source code referred to in this document please refer to this application.  (Additionally, you may also refer to this standalone Android application provides demo of API integrations that are provided by CommCare.)

First, in our AndroidManifest.xml we will need to register an intent-filter to listen for CommCare's call out. This will look like:

AndroidManifest.xml
Code Block
languagexml
<manifest>
...
    <application
	...
        <activity
            android:name=".CalloutActivity"
            android:label="@string/app_name" >
            <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <action android:name="callout.commcare.org.dummycallout.LAUNCH" />
            </intent-filter>
        </activity>
	...
    </application>
</manifest>

...

Next, in the activity's onCreate() method we parse the Extras from the intent bundle:

CalloutActivity.java
Code Block
languagejava
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
		...
 
        Bundle mBundle = getIntent().getExtras();
        //this is how we read in values sent by CommCare
        String caseid = mBundle.getString("case_id", null);

...

Finally, after this external application has done all of its work, we package up our results in a response. There are two ways of adding resultant data:

onClick
Code Block
languagejava
                String text = entryBox.getText().toString();
                Intent data = new Intent();

                //this is how you would add responses to the default bundle.
                Bundle responses = new Bundle();
                responses.putString("example_id", "Example text");
                data.putExtra("odk_intent_bundle", responses);

                // this is the value that CommCare will use as the result of the intent question
                data.putExtra("odk_intent_data", text);
                setResult(Activity.RESULT_OK, data);
                finish();

...