Through broker.media.* services, we can have access to camera and photo gallery functions of the device.

PUBLIC METHODS

Bool broker.media.hasCamera()

It returns true if the device has access to a camera. Otherwise, it returns false.

Return  
Bool It returns true if the device has access to a camera. Otherwise, it returns false.

Bool broker.media.hasCameraAccess()

It returns true if the device has access to a camera. Otherwise, it returns false. The first time this method is run, it will ask the user for permits.

Return  
Bool It returns true if the device has access to a camera. Otherwise, it returns false.

Bool broker.media.hasGalleryAccess()

It returns true if the device has access to the photo gallery. Otherwise, it returns false. The first time this method is run, it will ask the user for permits.

Return  
Bool It returns true if the device has access to the photo gallery. Otherwise, it returns false.


MediaFile broker.media.open(MediaCameraConfigure cameraConf)

It opens the camara with the options set up in the argument (See MediaCameraConfigure). When taking a photo or recording a video, it returns a MediaFile.

Parameters  
cameraConf MediaCameraConfigure: camara configuration.
Return  
MediaFile It returns a MediaFile with a captured photo or video.
Exceptionss
DeviceWithoutCamera – The device has no camera.
CameraAccessDenied – Error trying to access camera without permission.

MediaFile broker.media.open(MediaGalleryConfigure galleryConf)

It opens the photo gallery with the options configured in the argument (see MediaGalleryConfigure). When selecting a photo or video, it returns the call with the same photo or video in a MediaFile.

Parameters  
galleryConf MediaGalleryConfigure: gallery configuration.
Return  
MediaFile It returns a MediaFile with the photo or video selected.
Exceptions  
GalleryAccessDenied – Error trying to access media gallery without permission.  

void broker.media.removeTemporaryFiles()

It removes all the temporary files which were created by getURL(). In the case there are no files, nothing happens.

Exceptions  
RemoveTemporaryFilesException – Has been an exception when trying to remove temporary media files. This exception is thrown in case there are files but they cannot be erased.

Example:

Experience Main {
    String name label("Main name")
    String imagen as Image
    Decision rule1 action("MainContext.openCamera")  label("Open Camera")
    Decision rule2 action("MainContext.openGallery")  label("Open Gallery")
}

RuleContext MainContext {

  Rule openCamera {
    if (broker.media.hasCameraAccess()) {
      MediaCameraConfigure mcc = MediaCameraConfigure()
      mcc.setOnlyPhotosMode()
      //open camera
      MediaFile file = broker.media.open(mcc)
      if (file != null) {
        imagen = file.getURL()
      } else {
        //user has cancelled take photo action 
      }
    }
  }

  Rule openGallery {
    if (broker.media.hasGalleryAccess()) {
        MediaGalleryConfigure mgc = MediaGalleryConfigure()
        mgc.setOnlyPhotosGalleryMode()
        //open image gallery
        MediaFile file = broker.media.open(mgc)
        if (file != null) {
          imagen = file.getURL()
        } else {
          //user has cancelled pick photo action 
        }
    }
  }
}