This repository contains the files of the Sternum Android SDK, a versatile and flexible tool for implementing Relay applications and adding observability and traceability into Android devices using Java and C/C++.
For introduction and integration information, refer to the Online documentation.
How to import the SDK
Add SDK library to the project
Add the sternum-sdk-[release/debug].aar
file under the app/libs
directory in the target's project.
Declare SDK dependency
Add a dependencies in target's build.gradle
file:
- Including release:
dependencies {
implementation files('libs/sternum-sdk-release.aar')
}
- Debug/release specific configuration:
dependencies {
debugImplementation files('libs/sternum-sdk-debug.aar')
releaseImplementation files('libs/sternum-sdk-release.aar')
}
For more information refer to https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-gradle-for-android.
Using the API
The Sternum Android SDK offers two interfaces: Java API (com.sternum.cloud.SternumSDK) and the native API (sternum_sdk.h).
Import SDK
To use the component within your code, add the following import:
import com.sternum.cloud.SternumSDK;
import com.sternum.cloud.protocol.tracing.Argument;
// Trace definition file which is obtained from SDK Configurator application.
// The package/path is specific to your project.
import com.example.example.TraceEventType;
// Argument definition file which is obtained from SDK Configurator application.
// The package/path is specific to your project.
import com.example.example.ArgumentRoleType;
Initialize the SDK
❗ Important: The SDK can only be initialized from the Java API.
If you plan to use the SDK native API (with or without the Java API), link your native component with sternum_sdk_static.a
. Note that sternum_sdk_static.a
implements JNI_OnLoad
. If you encounter linking issues, please reach out to Sternum support. Then, invoke the initialization routine with loadNative=false
.
Legacy API
Deprecated: This method is deprecated and kept for backward compatibility. It is recommended to switch to the new initialization API to benefit from additional features like user-defined callbacks.
If you plan to use native API, invoke the initialization routine as follows:
SternumSDK sternumSDK = SternumSDK.getInstance();
sternumSDK.initialize(getApplicationContext(), "gateway.sternum.cloud",
true, new BigInteger("1234123412341234"),
SternumSDK.DeploymentPhase.PRODUCTION, 0x2000, false);
If you plan to use only the Java API, invoke the initialization routine as follows:
SternumSDK sternumSDK = SternumSDK.getInstance();
sternumSDK.initialize(getApplicationContext(), "gateway.sternum.cloud",
true, new BigInteger("1234123412341234"),
SternumSDK.DeploymentPhase.PRODUCTION, 0x2000, true);
New API (Recommended)
Recommended: Use the new flexible initialization method, which supports optional user-defined callbacks.
- Obtain the SDK Instance: Use
SternumSDK.getInstance()
to get the singleton instance of the SDK.
- Configure com.sternum.cloud.SternumSDKSettings.
- Set com.sternum.cloud.SternumTransmissionCallbacks (optional):
transmissionStarted
: Triggered when a transmission starts.
transmissionFinished
: Triggered when a transmission finishes, providing the number of packets and bytes transmitted.
packetsLost
: Triggered when packets are lost, providing the number of lost packets and bytes.
error
: Triggered when an error occurs, providing the error code and message.
- Initialize the SDK: Call
initialize
with the application context and the configured settings.
Example Code:
SternumSDK sternumSDK = SternumSDK.getInstance();
sternumSDKSettings = new SternumSDKSettings();
sternumSDKSettings.sternumURL = "your.gateway.com";
sternumSDKSettings.firmwareVersion = "your.firmware.version";
sternumSDKSettings.relayOverrideDeviceID = true;
sternumSDKSettings.accessToken = new BigInteger("1234567890");
sternumSDKSettings.isProduction = false;
sternumSDKSettings.maxCacheSizeBytes = 10000;
sternumSDKSettings.loadNative = true;
sternumSDKSettings.callbacks.transmissionStarted = () -> {
};
sternumSDKSettings.callbacks.transmissionFinished = (long packets, long bytes) -> {
};
sternumSDKSettings.callbacks.packetsLost = (long packets, long bytes) -> {
};
sternumSDKSettings.callbacks.error = (int errorCode, String error) -> {
};
sternumSDK.initialize(mAppContext, mSternumSDKSettings);
Sending traces
sternumSDK = SternumSDK.getInstance();
sternumSDK.trace(TraceEventType.TRACE_OS_INFORMATION,
new Argument(ArgumentRoleType.ARG_ROLE_NAME, "Android"),
new Argument(ArgumentRoleType.ARG_ROLE_VERSION, Build.VERSION.SDK_INT));
Relaying device data
sternumSDK = SternumSDK.getInstance();
sternumSDK.relayDeviceData(SternumSDK.DeviceType.DEVICE_TYPE_A, deviceReceivedData);