Skip to content
cketcham edited this page Jun 27, 2012 · 5 revisions

RemoteActivity allows for the creation of a customized prompt written specifically for a campaign.

How to create a remote activity

  1. Write an android application with at least one activity which returns a Bundle with at least one key, 'score', whose value is a double.
  2. Specify the prompt in your campaign XML as defined in the Campaign Definition Page
  3. Install both ohmage and the android application which contains the remote activity on the phones you are using.

Example

After a remote activity is finished collecting data, it should set the correct result (Activity.RESULT_OK or Activity.RESULT_CANCELED), a double value with the key 'score', and an optional feedback string which will be shown to the user with the key 'feedback'. Any other keys and values can be included and will be transformed into a JSON object which will be uploaded with the response.

public static final String KEY_SCORE = "score";
public static final String KEY_FEEDBACK = "feedback";

Bundle extras = new Bundle();

double userScore = calculateScore();
// Score is required
extras.putDouble(KEY_SCORE, userScore);
// Feedback string is optional
extras.putString(KEY_FEEDBACK, "Your score for this game was: " + userScore);

// Extra data which will be converted to JSON
extras.putInt(REPORT_GOOD_CHAR_HITS, numGoodItemHits);
extras.putInt(REPORT_BAD_CHAR_HITS, numBadItemHits);
extras.putInt(REPORT_GOOD_CHAR_MISSES, numGoodItemMisses);
extras.putInt(REPORT_BAD_CHAR_SKIPS, numBadItemSkips);
extras.putInt(REPORT_REPEAT_TAPS, numRepeatTaps);
extras.putString(REPORT_RESPONSE_TIMES, responseTimes.toString());

Intent results = new Intent();
results.putExtras(extras);

// The result is set and the remote activity is finished.
setResult(Activity.RESULT_OK, results);
finish();

In the AndroidManifest.xml you will need to specify the remote activity so it can be used by ohmage:

<activity android:name=".Game" android:exported="true">
	<intent-filter>
		<action android:name="edu.ucla.cens.FocusGame.Game.LAUNCH"/>
	</intent-filter>
</activity>

Last, you need to define the remote activity prompt in the campaign xml:

<prompt>
	<id>AttentionGame</id>
	<displayType>event</displayType>
	<displayLabel>Attention Game</displayLabel>
	<unit>Score</unit>
	<promptText>Press the button below to play the game. To play, tap every letter except the letter 'X'.</promptText>
	<abbreviatedText>Attention Game</abbreviatedText>
	<promptType>remote_activity</promptType>
	<properties>
		<property>
			<key>package</key>
			<label>edu.ucla.cens.FocusGame</label>
		</property>
		<property>
			<key>activity</key>
			<label>edu.ucla.cens.FocusGame.Game</label>
		</property>
		<property>
			<key>action</key>
			<label>edu.ucla.cens.FocusGame.Game.LAUNCH</label>
		</property>
		<property>
			<key>autolaunch</key>
			<label>false</label>
		</property>
		<property>
			<key>retries</key>
			<label>10</label>
		</property>
		<property>
			<key>min_runs</key>
			<label>1</label>
		</property>
	</properties>
	<skippable>true</skippable>
	<skipLabel>Skip</skipLabel>
</prompt>
Clone this wiki locally