Skip to content

Commit

Permalink
Adds support lib method to launch CC with an App
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Sep 22, 2023
1 parent 6b8f974 commit b57bc5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/src/org/commcare/activities/DispatchActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.commcare.activities;

import static org.commcare.commcaresupportlibrary.CommCareLauncher.SESSION_ENDPOINT_APP_ID;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -35,7 +37,6 @@ public class DispatchActivity extends AppCompatActivity {
private static final String TAG = DispatchActivity.class.getSimpleName();
private static final String SESSION_REQUEST = "ccodk_session_request";
public static final String SESSION_ENDPOINT_ID = "ccodk_session_endpoint_id";
public static final String SESSION_ENDPOINT_APP_ID = "ccodk_session_endpoint_app_id";

// Args to session endpoints can be passed as a name to value bundle or more loosely as a list
public static final String SESSION_ENDPOINT_ARGUMENTS_BUNDLE = "ccodk_session_endpoint_arguments_bundle";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.commcare.activities.LoginActivity
import org.commcare.activities.StandardHomeActivity
import org.commcare.android.util.TestAppInstaller
import org.commcare.android.util.TestUtils
import org.commcare.commcaresupportlibrary.CommCareLauncher
import org.commcare.commcaresupportlibrary.CommCareLauncher.SESSION_ENDPOINT_APP_ID
import org.commcare.util.screen.CommCareSessionException
import org.commcare.utils.SessionUnavailableException
import org.junit.Assert.*
Expand Down Expand Up @@ -59,7 +61,7 @@ class ExternalLaunchTests {

private fun launchAndVerifyCCWithAppId(appId: String, nextScreen: String) {
val intent = Intent("org.commcare.dalvik.action.CommCareSession")
intent.putExtra(DispatchActivity.SESSION_ENDPOINT_APP_ID, appId)
intent.putExtra(SESSION_ENDPOINT_APP_ID, appId)
var dispathActivity =
Robolectric.buildActivity(DispatchActivity::class.java, intent).create().resume().get()
var recordedNextIntent = Shadows.shadowOf(dispathActivity).nextStartedActivity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.commcare.commcaresupportlibrary;

import android.content.Context;
import android.content.Intent;

/**
* Utility class with methods to launch CommCare
*/
public class CommCareLauncher {
public static final String SESSION_ENDPOINT_APP_ID = "ccodk_session_endpoint_app_id";
private static final String CC_LAUNCH_ACTION = "org.commcare.dalvik.action.CommCareSession";

/**
*
* @param context Android context to launch the CommCare with
* @param appId Unique Id for CommCare App that CommCare should launch with
*/
public static void launchCommCareForAppId(Context context, String appId) {
Intent intent = new Intent(CC_LAUNCH_ACTION);
intent.putExtra(SESSION_ENDPOINT_APP_ID, appId);
context.startActivity(intent);
}
}

0 comments on commit b57bc5f

Please sign in to comment.