Skip to main content

Android - Method Module Interface

The MethodModule interface is used when you need to run native logic without requiring any UI elements. It supports two distinct patterns:

  1. Tecton-triggered calls — Tecton invokes a method on your module and receives a string callback in return.
  2. Core-initiated requests — The Q2 application requests structured data from your module using a typed MethodRequest.

Tecton-Triggered Implementation

note

To call a MethodModule from Tecton, a Tecton Caliper extension is required. Please refer to the Caliper guides to get started.

To implement a Tecton-triggered MethodModule:

  1. Create a class and inherit from MethodModule.
  2. Define a function to handle your desired logic.
  3. Once the operation is complete, trigger the MethodModule.MethodModuleCallback to return the result.
Sample MethodModule Implementation
class TestMethodModule(private val sdkUtils: SdkUtils): MethodModule {

fun testMethod(context: Context, data: String, callback: MethodModule.MethodModuleCallback) {
// Once you are done, trigger the callback and send back the data you want.
callback.returnValue(data)
}
}

To call your MethodModule from Tecton, follow the Tecton - callModule guide.

Core-Initiated Requests

The MethodModule interface also supports an optional request function that allows your module to respond to typed requests from the Q2 application and return structured JSON data:

suspend fun request(request: MethodRequest): JSONObject? = null

The default implementation returns null, so existing MethodModule implementations require no changes. Rather than introducing a new interface for each one-off requirement, a new MethodRequest enum value is defined per use case. The shape of the returned JSONObject is defined per request type.

MethodRequest: OAUTH_AUTHORIZATION_PARAMS

Appends key-value pairs to the following OAuth 2.0 operations in Q2's InboundSSO authentication module. All data is URL encoded by InboundSSO before being added.

  • /authorization — key-value pairs are appended to the authorization URL as query parameters
  • /refresh — key-value pairs are added to the body of the refresh token request

Expected return format:

{
"foo": "foo value"
}

Module implementation example:

class MyMethodModule : MethodModule {
override suspend fun request(request: MethodRequest): JSONObject? {
return if (request == MethodRequest.OAUTH_AUTHORIZATION_PARAMS) {
JSONObject().apply {
put("foo", "foo value")
}
} else {
null
}
}
}

Update Your settings.json

Ensure your settings.json file in the root of the DevApp is updated to reflect your module changes. Learn more in Configuring settings.json.