3. Initialisation
OctopusTMS is a thread-safe singleton. You must obtain the instance using getInstance() and call initialize() before any other method.
3.1 getInstance()
val pos = OctopusTMS.getInstance(
context = applicationContext,
config = OctopusTMS.Config(
appName = "MyApp",
enableLogs = BuildConfig.DEBUG
)
)
OctopusTMS pos = OctopusTMS.getInstance(
getApplicationContext(),
new OctopusTMS.Config("MyApp", BuildConfig.DEBUG)
);
WARNING
Always pass applicationContext, never an Activity context.
3.2 initialize()
pos.initialize { result ->
when (result) {
is OctopusTMS.InitResult.Success -> {
Log.d(TAG,
"Connected: ${result.detectedOEM}")
}
is OctopusTMS.InitResult.Failed -> {
Log.e(TAG,
"Init failed: ${result.reason}")
}
is OctopusTMS.InitResult.UnsupportedDevice -> {
Log.e(TAG, "Unsupported device")
}
}
}
pos.initialize(result -> {
if (result instanceof OctopusTMS.InitResult.Success) {
OctopusTMS.InitResult.Success s =
(OctopusTMS.InitResult.Success) result;
Log.d(TAG, "Connected: " + s.getDetectedOEM());
} else if (result instanceof OctopusTMS.InitResult.Failed) {
OctopusTMS.InitResult.Failed f =
(OctopusTMS.InitResult.Failed) result;
Log.e(TAG, "Init failed: " + f.getReason());
} else if (result instanceof OctopusTMS.InitResult.UnsupportedDevice) {
Log.e(TAG, "Unsupported device");
}
});
InitResult Sealed Class
| Result | Meaning | Key Field |
|---|---|---|
| InitResult.Success | SDK connected to hardware service successfully | detectedOEM |
| InitResult.Failed | SDK could not connect to the hardware service | reason: String |
| InitResult.UnsupportedDevice | Device OEM is not supported by this SDK version | — |