The aim of this document is to assist you in retrieving device information from your custom application running on the Nomba Android terminal. If you encounter any difficulties with this process, feel free to reach out for support.

Retrieve device info - available since NombaX Application v1.6.2

This following code snippet serves as a foundation for retrieving device information on the Nomba terminal.

import android.app.Activity;
import android.content.Intent;
import androidx.activity.result.ActivityResultContracts;
import androidx.activity.result.ActivityResultLauncher;
import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

const val TERMINAL_ID = "terminalId"
const val SERIAL_NO = "serialNo"
const val DEVICE_INFO_ARGUMENTS = "deviceInfoArguments"
const val DEVICE_INFO_RESULT = "deviceInfoResult"
const val DEVICE_INFO_INTENT = "com.nomba.pro.feature.device_setup.ACTION_VIEW"

val resultString = mutableStateOf("")
var deviceInfoResult = HashMap<String, String>()
val gson = GsonBuilder()
    .setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
    .create()

//setup a launcher that would help launch the intent
var deviceInfoResultLauncher = registerForActivityResult(
    ActivityResultContracts
        .StartActivityForResult()
) { result ->
    val data: Intent? = result.data
    if (result.resultCode == Activity.RESULT_OK) {
        val type = object : TypeToken<HashMap<String, Any>>() {}.type
        val resultJson = data?.getStringExtra(DEVICE_INFO_RESULT)
        deviceInfoResult = gson.fromJson(resultJson, type)

        val terminalId = deviceInfoResult[TERMINAL_ID]
        val serialNo = deviceInfoResult[SERIAL_NO]
        resultString.value = "Terminal Id: $terminalId Serial No: $serialNo"
    }
}

//setup an intent to be triggered
val intent = Intent(DEVICE_INFO_INTENT)

//pass the terminalId and serialNo as extra data
intent.putExtra(DEVICE_INFO_ARGUMENTS, "$TERMINAL_ID,$SERIAL_NO")

//launch the intent
deviceInfoResultLauncher.launch(intent)

Your resultString should look like;

Terminal Id: 2KUD4AKB Serial No: 1234567890