Class RunLearningUnitRequest

java.lang.Object
com.eidu.integration.RunLearningUnitRequest

public final class RunLearningUnitRequest extends Object
A RunLearningUnitRequest is what the EIDU app uses to launch a learning unit from integrated learning apps.

The EIDU app will send an intent to your app, identified by the intent action (See Intent.setAction(String)) and include all data relevant for you to identify the learning unit to run.

The intent sent also includes references to the learner and their school.

The easiest way to obtain the data provided by the Intent sent from EIDU is fromIntent(Intent), which will automatically identify and extract all information included in Intent.getExtras().

Use getAssetAsStream(Context, String), getAssetAsFileDescriptor(Context, String), or getAssetAsUri(String) to retrieve any assets required by the requested learning unit.

To facilitate testing of your app, you can create your own RunLearningUnitRequest with of(String, String, String, String, String, Long, Long, Uri) and convert it to an Intent with toIntent(String, String).

  • Field Details

    • version

      public final int version
    • learningUnitId

      @NonNull public final String learningUnitId
      An ID, defined by the learning app, that uniquely identifies the learning unit to run.
    • learningUnitRunId

      @NonNull public final String learningUnitRunId
      A unique identifier of each learning unit run, which may be used for reporting purposes.
    • learnerId

      @NonNull public final String learnerId
      The obfuscated ID of the learner who is playing the learning unit. May be used for reporting purposes.
    • schoolId

      @NonNull public final String schoolId
      The obfuscated ID of the school at which the learning unit is being played. May be used for reporting purposes.
    • stage

      @NonNull public final String stage
      Identifies the stage of the EIDU app, e.g. "test", "prod". May be used for reporting purposes.
    • remainingForegroundTimeInMs

      @Nullable public final Long remainingForegroundTimeInMs
      Optional. The maximum amount of time that this run may take. The learning app must end the run with RunLearningUnitResult.ResultType.TimeUp after this amount of foreground time has elapsed.
    • inactivityTimeoutInMs

      @Nullable public final Long inactivityTimeoutInMs
      Optional. The time of user inactivity after which the learning app must end the run with RunLearningUnitResult.ResultType.TimeoutInactivity.
  • Method Details

    • of

      @NonNull public static RunLearningUnitRequest of(@NonNull String learningUnitId, @NonNull String learningUnitRunId, @NonNull String learnerId, @NonNull String schoolId, @NonNull String stage, @Nullable Long remainingForegroundTimeInMs, @Nullable Long inactivityTimeoutInMs, @Nullable Uri assetsBaseUri)
      Creates a new RunLearningUnitRequest instance.

      Use this to test your learning app against what the EIDU app will send to launch a learning unit.

      Parameters:
      learningUnitId - Required, see learningUnitId.
      learningUnitRunId - Required, see learningUnitRunId.
      learnerId - Required, see learnerId.
      schoolId - Required, see schoolId.
      stage - Required, see stage.
      remainingForegroundTimeInMs - Optional, see remainingForegroundTimeInMs.
      inactivityTimeoutInMs - Optional, see inactivityTimeoutInMs.
      assetsBaseUri - Optional, the base content URI from which to retrieve assets.
      Returns:
      The new instance.
    • fromIntent

      @Nullable public static RunLearningUnitRequest fromIntent(@NonNull Intent intent) throws IllegalArgumentException
      Creates a new RunLearningUnitRequest instance from the provided intent.

      Use this on the intent sent to your learning app by EIDU to get access to the necessary data.

      Parameters:
      intent - Required, the intent sent from the EIDU app to your learning app.
      Returns:
      The new RunLearningUnitRequest instance, initialized from the provided intent, or null if intent was not a request to run a learning unit
      Throws:
      IllegalArgumentException - If the provided intent does not contain all required data.
    • toIntent

      @NonNull public Intent toIntent(@NonNull String packageName, @NonNull String className)
      Creates an explicit intent usable to launch a learning app.

      You can use this method, along with of(String, String, String, String, String, Long, Long, Uri) to test your app.

      Parameters:
      packageName - The package name of the learning app.
      className - The class name of the activity to launch with this intent
      Returns:
      An intent for the given package and class, containing all the launch information.
    • getAssetAsStream

      @NonNull public InputStream getAssetAsStream(@NonNull Context context, @NonNull String path) throws FileNotFoundException
      Retrieves the contents of an asset as an InputStream. It is the caller's responsibility to close this stream after use.
      Parameters:
      context - The current context. May be an application context.
      path - The path of the asset to retrieve.
      Returns:
      An InputStream from which the asset's contents can be read.
      Throws:
      FileNotFoundException - In case an asset by that name cannot be found for the learning unit being run, the request does not support asset loading, or EIDU has crashed.
    • getAssetAsUri

      @NonNull public Uri getAssetAsUri(@NonNull String path) throws FileNotFoundException
      Retrieves a content Uri for an asset, which can be used, for example, with MediaPlayer.

      At this point, it is not guaranteed that the Uri points to a valid asset.

      Parameters:
      path - The path of the asset to retrieve.
      Returns:
      A Uri from which the asset's contents can be read.
      Throws:
      FileNotFoundException - In case the request does not support asset loading.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object