Android - SDKUtils
Overview
SdkUtils
is an abstract class that provides essential utilities and access to core
functionalities for SDK modules. It serves as the primary interface between your module
and the core application, allowing you to access system resources, user information,
navigation controls, and more.
The class implements Parcelable
, enabling it to be passed between Android components
efficiently.
Class Declaration
abstract class SdkUtils(private val sdkModuleConfig: SdkModuleConfig): Parcelable
Key Methods
Application and Context Access
Method | Description |
---|---|
getApplication(): Application | Provides the global Application for Core. |
getApplicationContext(): Context | Provides the Context of the global Application . |
getActivity(): Activity? | Provides access to the currently displayed activity. Activity will not be available until after LifecycleModule.onCreate when the first activity is created. Returns null during or before this time, or during the stopped state if a new activity is not created. |
User Authentication and Information
Method | Description |
---|---|
getQ2Token(): String? | Returns the current user's Q2 Token. Returns null if no user has signed in or the current user has lost authentication. |
getCurrentUserName(): String? | Returns the username of the currently authenticated user. |
getCurrentUserId(callback: GetUserIdCallback) | Returns the ID of the currently authenticated user through the provided callback. |
URL and Path Management
Method | Description |
---|---|
getBaseUrl(): String | Returns the base URL for API calls. |
getUUXUrl(): String | Returns the URL for the UUX (User Experience) components. |
loadPathInUuxViewBeforeLogon(path: String) | Redirects the Core's web view to a new pathing route before logon. Only works if the application is in foreground and Core has control of the current view. |
loadPathInUuxViewAfterLogon(path: String) | Redirects the Core's web view to a new pathing route after logon. Only works if the application is in foreground and Core has control of the current view. |
runJavascriptInUUX(javaScript: String, callback: ValueCallback<String>?) | Executes JavaScript code in the running web view. Only works if the application is in foreground and Core has control of the current view. |
Theme and UI Resources
Method | Description |
---|---|
getCurrentThemeName(): String? | Returns the name of the current theme. |
getCurrentTheme(): JSONObject? | Returns the current theme as a JSON object. |
getColor(id: String): String? | Returns a color value from the current theme by its identifier. |
getString(id: String): String? | Returns a string value from resources by its identifier. |
getFont(id: String): Typeface | Returns a font Typeface from resources by its identifier. |
Device Information
Method | Description |
---|---|
getUserDefinedDeviceName(): String | Returns the user-defined name of the device. |
getDeviceID(): String | Returns the unique identifier for the device. |
UI Controls
Method | Description |
---|---|
showLoadingView() | Displays the built-in loading view over the web view. Only works if the application is in foreground and Core has control of the current view. |
hideLoadingView() | Hides the built-in loading view if already being displayed. |
showDialogFragment(dialog: DialogFragment) | Shows a DialogFragment. |
showFragment(fragment: Fragment) | Shows a Fragment. |
hideFragment() | Hides the currently displayed Fragment. |
Logging and Analytics
Method | Description |
---|---|
logEvent(eventName: String, data: Map<String, String>) | Logs an event with the specified name and associated data. |
Configuration and Settings
Method | Description |
---|---|
getSetting(name: String): String? | Returns a setting value by its name. |
getSdkModuleConfig(): SdkModuleConfig | Returns the SDK module configuration provided during initialization. |
getQ2ConfigObject(callback: Q2ConfigResponseCallback) | Retrieves the Q2 configuration object through the provided callback. |
getSSOContent(vendorId: Int, callback: SSOContentResponseCallback) | Retrieves SSO content for the specified vendor through the provided callback. |
Push Notifications
Method | Description |
---|---|
isSacViaPushAllowed(): Boolean | Checks if Secure Account Creation via push notifications is allowed. |
getSDKPushUtils(): SDKPushUtils | Returns the push notification utilities. |
Intent Management
Method | Description |
---|---|
getLaunchIntent(): Intent | Returns the launch intent for the application. |
Associated Interfaces
SSOContentResponseCallback
Callback interface for handling SSO content responses.
interface SSOContentResponseCallback {
fun onReceivingSSOContent(responseString: String?)
fun onReceivingErrorContent(errorResponseString: String?)
fun onFailure(exception: Throwable)
}
Q2ConfigResponseCallback
Callback interface for handling Q2 configuration object responses.
interface Q2ConfigResponseCallback {
fun onReceivingQ2ConfigObject(responseObject: JSONObject?)
fun onReceivingErrorContent(errorResponseString: String?)
fun onFailure(exception: Throwable)
}
GetUserIdCallback
Callback interface for retrieving the user ID.
interface GetUserIdCallback {
fun value(userId: String?)
}
SDKPushUtils
Interface providing access to push notification utilities.
interface SDKPushUtils {
val pushRegistrationToken: String?
val deviceNickname: String?
val isEnabledForSAC: Boolean
val isPushEnabled: Boolean
val isPushEnabledAtOS: Boolean
val pushUserId: Int
}
Usage Example
class BaseUrlMethodModule(private val sdkUtils: SdkUtils) : MethodModule {
fun getBaseUrl(context: Context, data: String, callback: MethodModule.MethodModuleCallback) {
// Get the application context
val context = sdkUtils.getApplicationContext()
// Check if user is authenticated
val token = sdkUtils.getQ2Token()
if (token != null) {
// User is authenticated
val username = sdkUtils.getCurrentUserName()
// Get user ID and return it
sdkUtils.getCurrentUserId(object : GetUserIdCallback {
override fun value(userId: String?) {
callback.returnValue(userId ?: "")
}
})
} else {
callback.returnValue("")
}
}
}
Notes
- Many methods will only function correctly when the application is in the foreground and the Core has control of the current view.
- Authentication-dependent methods may return null if no user is authenticated.
- Callbacks are used for asynchronous operations to prevent blocking the main thread.