How do I call the thermal camera in an app?

The Thermal Camera works natively inside the RealWear My Camera App. To access this app inside your own app you'll need to understand how Android intents work and apply these to your app, we've provided some information below.

RealWear's My Camera app supports 3rd party intents to directly open the Thermal Camera Activity and have FLIR Radiometric Thermal JPEGS returned in the URI.

Required Manifest Permissions

 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

Thermal Intent types

  1. Thermal Image preferred.

  2. Thermal Image required.

Use-cases

  1. THERMAL OPTION 1 is for a developer wanting to launch a ACTION_IMAGE_CAPTURE intent to prefer the Thermal Camera Activity while allowing the end-user the option to switch to the Main Visual Camera or vise versa.

    1. NOTE, if a thermal module is not present, a WARNING dialog will be presenting to the end-user then switch to the Main Visual Camera.

  2. THERMAL OPTION 2 is for a developer wanting to launch a ACTION_IMAGE_CAPTURE intent to require the Thermal Camera Activity.

    1. NOTE, if a thermal module is not present, ERROR dialog will be presenting to the end-user then close the camera application.

    2. Developers should do properly error handling of the returned resultCode to see if the take photo operation was Activity.RESULT_CANCELED or Activity.RESULT_OK

Thermal Image Capture:

Overview

  • The 3rd party will define a URI with the expected:

    1. MIME_TYPE = “image/jpg”

    2. NAME = “my_photo.jpg”

    3. and the relative path to this URI

  • Create an image capture intent with:

    1. put an intent extras MediaStore.EXTRA_OUTPUT with the developer defined URI defined above, as the value.

    2. attach a camera mode string identifying this is either:

      1. THERMAL OPTION 1(thermal) to the extras key rw_camera_mode

      2. THERMAL OPTION 2(req-thermal) to the extras key rw_camera_mode

  • take a photo

  • In the returned activity result intent will be extras:

  • key = MediaStore.EXTRA_OUTPUT, value = URI defined by the 3rd party app

  • key = temperature, value = the temperature, in Celsius as a String, of the area or spot meter, if selected.

Code Example

  1. 3rd party call to thermal camera:

     
    fun takePhoto() {
    val thermalContentValues = ContentValues().apply {
    put(MediaStore.MediaColumns.DISPLAY_NAME, "my_photo.jpg") put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg")  put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM) 
    }
    val thermalContentUri = baseContext.contentResolver.insert(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
    thermalContentValues 12
    )

    val cameraRequestCode: Int = 1337
    val imageCaptureIntent: Intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
    addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
    putExtra(MediaStore.EXTRA_OUTPUT, thermalContentUri) 

    // "thermal" for OPTION 1 
    // "req-thermal" for OPTION 2 
    putExtra("rw_camera_mode", "thermal") 

    startActivityForResult(imageCaptureIntent, cameraRequestCode)
    }

     

  2. Activity Result:

     
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    val cameraRequestCode: Int = 1337 
    if (resultCode == Activity.RESULT_OK && requestCode == cameraRequestCode) { 
    data?.let { cameraIntent ->
    val imageUri = cameraIntent.data as? Uri 
    imageUri?.also { findViewById(R.id.imageView).setImageUri(it)} 


    super.onActivityResult(requestCode, resultCode, data)
    }