Camera Intents

Overview

RealWear’s My Camera provides two default solutions for 3rd party apps to open My Camera, capture an image and return the image to the calling app.

NOTE, when a thermal module is connected:

OPTION 1 will return a bitmap thermal image without Radiometric data.

OPTION 2 will save a FLIR Radiometric Thermal jpg at the URI provided by the 3rd party app.

See My Camera: Thermal Image Capture Intent(CameraX)

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" />

Use-cases

  • OPTION 1, Developers looking to capture an image and have a bitmap returned to display to the user.

  • OPTION 2, Developers trying to capture an image and get the full high resolution image saved to a specific file location(URI) with a specific name.

Image Capture

Overview

  • OPTION 1

    1. 3rd party app will use an image capture action intent to open the RealWear My Camera app

    2. take a photo

    3. In the returned activity result intent will be an extra where it’s key will be data and it’s value will be a bitmap image:

      1. The return intent will have a bitmap for the calling application to return

  • OPTION 2

    1. 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

    2. use an image capture intent to open the RealWear My Camera app and attach the URI defined above to the extra key MediaStore.EXTRA_OUTPUT

    3. take a photo

    4. In the returned activity result intent will be an extras key MediaStore.EXTRA_OUTPUT with the same URI defined by the 3rd party app

Code Example

OPTION 1 (Bitmap)

  • 3rd party call to My Camera app:

     
    fun takePhoto() { 
    val cameraRequestCode: Int = 1337 
    val imageCaptureIntent: Intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) 

    startActivityForResult(imageCaptureIntent, requestCode)
    }

     

  • Activity Result:

     
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 
    if (resultCode == Activity.RESULT_OK && requestCode == cameraRequestCode){ 
    data?.let { cameraIntent -> 
    cameraIntent.extras?.get("data")?.let { imageFromCamera -> 
    findViewById(R.id.imageView).setBitmapImage(imageFromCamera) 


    }
    }

OPTION 2 (Image URI)

  • 3rd party call to My Camera app:

     
     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) 7 } 

     val thermalContentUri = baseContext.contentResolver.insert( 
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
    thermalContentValues 


    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) 


    startActivityForResult(imageCaptureIntent, cameraRequestCode)
    }

    Activity Result:

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 
    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)
    }