Calling Intents using Android App Callout

51 views
Skip to first unread message

Tim Butler

unread,
Aug 12, 2014, 12:50:21 PM8/12/14
to commcare-...@googlegroups.com
Hi,

I am using the Android App Callout to test using intents

I am struggling with the syntax and could do with a hand.
I am using the build in alarm as an example.

Intent ID: android.intent.action.SET_ALARM 

Extra
android.intent.extra.alarm.MESSAGE  Wakey Wakey
android.intent.extra.alarm.HOUR         12
android.intent.extra.alarm.MINUTES    23

The app wont install as soon as I add the Extras. 

I have tried just the shortened MESSAGE, HOUR and MINUTES.

Would it be possible to have a simple example of the correct syntax for Intents including the Response using one of the Standard Android intents and to another App?

Much thanks in advance

Tim



William Pride

unread,
Aug 12, 2014, 1:21:49 PM8/12/14
to commcare-...@googlegroups.com
Tim,

Form builder expects the values to be paths to data rather than hard coded values. So, these either need to be the paths to a question or, more likely, a hidden value with a calculate expression of the proper value.

For example, your extra key might be:

android.intent.extra.alarm.MESSAGE

And the value would be:

/data/hidden_value_1

With hidden_value_1 having the calculate expression 'Wakey Wakey'

I can see our documentation isn't clear enough on that point and I'll fix that shortly - sorry about that.

Thanks,
Will



--

---
You received this message because you are subscribed to the Google Groups "CommCare Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-develo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Butler

unread,
Aug 20, 2014, 4:22:22 AM8/20/14
to commcare-...@googlegroups.com
Hi 

With Will's advice I have now got the following working:

Intent ID: com.xxxxxxx.android.app.INTENTCALL

Extra:
IntentVariable1 > /data/HiddenIntVar1
IntentVariable2 > /data/HiddenIntVar2

where /data/HiddenIntVar1 and /data/HiddenIntVar2 are populated from the form.

I am struggling on the response:
ResponseVariable1 > /data/HiddenResVar1

Am I missing something?

Best

Tim

Tim Butler

unread,
Aug 22, 2014, 5:32:43 AM8/22/14
to commcare-...@googlegroups.com

I have now got the Called App to return a string to another dummy program. So now launches the program, scans the value and responds with a single string.

When I launch with CommCare ODK the program, scans the value and then crashes ODK with the following message:
08-22 10:03:18.735: E/AndroidRuntime(13771): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10, result=-1, data=Intent { (has extras) }} to activity {org.xxxxx.demolog/org.odk.collect.android.activities.FormEntryActivity}: java.lang.NullPointerException

Here is the code

Intent resultIntent = new Intent();
resultIntent.putExtra("BarCodes", single_barcode);
setResult(RESULT_OK, resultIntent);
finish();

In Commcare

Response BarCodes > /data/returnData

Am I missing something? Anyone else had some experience of this?

Much thanks in advance

Tim

William Pride

unread,
Aug 22, 2014, 5:41:48 AM8/22/14
to commcare-...@googlegroups.com
Tim,

CommCareODK actually expects either a single string value with key odk_intent_data and a value that that question will be set to and/or a Bundle called odk_intent_bundle with a set of key-value pairs, as specified at the bottom of this page. So your code here will actually look like:

Intent resultIntent = new Intent();
Bundle extras = new Bundle();
extras.putString("BarCodes",single_barcode);
setResult(RESULT_OK, resultIntent);
finish();

Best,
Will


Clayton Sims

unread,
Aug 22, 2014, 11:22:25 AM8/22/14
to commcare-...@googlegroups.com
Sorry about the somewhat confusing behavior in this regard.

It's not extremely common for applications to maintain a callout contract that is tremendously generic in some regards, and we didn't want to force collisions through people's standard app callouts. This behavior is currently functional but still something we're open to adapting. If you have comments on how you'd like the intent callout structure to work, feel free to either email here or make comments on our wiki at 


Thanks!
-Clayton

Tim Butler

unread,
Aug 27, 2014, 10:32:53 AM8/27/14
to commcare-...@googlegroups.com
Hi Clayton and Will

I got there in the end with Will's patience and help.

The Response was held in this code

@Override
public void onBackPressed() {

// Bundle
Intent resultIntent = new Intent();
        Bundle extras = new Bundle();
// "CommCareResponse1" can be any name you choose and is used to catch the repsonse in CommCare
        extras.putString("CommCareResponse1", programVariable1);
        extras.putString("CommCareResponse2", programVariable1);
resultIntent.putExtra("odk_intent_bundle", extras);
setResult(RESULT_OK, resultIntent);
finish();
super.onBackPressed();

}

Clayton, I think clearer step by step examples would have helped me a lot. As this is passing between programs, it takes a little time to ensure that both the send and receive work in both CommCare and the created app.

I also expected to be able to get response from any program api not just ones I can code myself. Not that much of an issue in this case but would be if we wanted to interface with other mainstream programs.

The last little thing is naming the button. It would be useful to be able to modify this through your interface.

For the record, it is working now and we have a real barcode scanner grabbing 1D barcodes in a split second on a rugged handset :)

Best

Tim

To unsubscribe from this group and stop receiving emails from it, send an email to commcare-developers+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "CommCare Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-developers+unsub...@googlegroups.com.

Clayton Sims

unread,
Aug 27, 2014, 10:42:27 AM8/27/14
to commcare-...@googlegroups.com
Great to hear that you got it working!

You should be able to translate the text of the button globally for the app currently. You can use the locale key:

odk_intent_callout_button

-Clayton


To unsubscribe from this group and stop receiving emails from it, send an email to commcare-develo...@googlegroups.com.

Tim Butler

unread,
Aug 28, 2014, 7:03:04 AM8/28/14
to commcare-...@googlegroups.com

Hi Clayton,

Thanks for this.

I need to have two varieties, one for scan and one for print.

Any ideas?

Best

Tim

You received this message because you are subscribed to a topic in the Google Groups "CommCare Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commcare-developers/XQ_Lb5z6K_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commcare-develo...@googlegroups.com.

Clayton Sims

unread,
Aug 28, 2014, 1:39:12 PM8/28/14
to commcare-...@googlegroups.com
Tim,

Unfortunately that isn't currently supported. We have an open issue to work on that feature.

-Clayton
Reply all
Reply to author
Forward
0 new messages