Principle:

After the mobilecam SDK sends a [Capture Photo] request to the camera and the camera finishes taking a photo, the camera will add a new file. At this time, the camera will send a [new file added] event to the mobilecam SDK. If the app registers a event listener to listen this event, the app will receive Such event notification too.

The content described in this article is available in V.3.6.0.21 and later.
_

About the API:

Event name

  • For java API

    1. // in file type/ICatchCamEvent.java
    2. ICatchCamEventID.ICH_CAM_EVENT_FILE_ADDED
  • For c++ API

    1. // in file type/ICatchCamEventID.h
    2. typedef enum ICatchCamEventID {
    3. ICH_CAM_EVENT_FILE_ADDED = 0x01,
    4. ....
    5. }

    Event parameters and usage

  • Get the newly added file object through getFileValue1 () of the ICatchCamEvent object.

  • For java API

    1. public class FileAddedListener implements ICatchCameraListener {
    2. @Override
    3. public void eventNotify(ICatchCamEvent arg0) {
    4. // The arg0.getFileValue1() returns the valid file object, see following code.
    5. handler.obtainMessage(EVENT_FILE_ADDED, arg0.getFileValue1()).sendToTarget();
    6. }
    7. }
  • For C++ API

    1. class FileAddedListener : public ICatchCameraListener
    2. {
    3. public:
    4. void eventNotify(shared_ptr<ICatchCamEvent> arg0) {
    5. // The arg0.getFileValue1() returns the valid file object, see following code.
    6. auto file = arg0->getFileValue1();
    7. printf("The newly added file, path: %s, name: %s\n",
    8. file->getFilePath().c_str(), file->getFileName().c_str());
    9. }
    10. }

Example:

1. Create EventListener class

  1. public class FileAddedListener implements ICatchCameraListener {
  2. @Override
  3. public void eventNotify(ICatchCamEvent arg0) {
  4. handler.obtainMessage(EVENT_FILE_ADDED, arg0.getFileValue1()).sendToTarget();
  5. }
  6. }

2. Handler‘s handleMessage callback. We save the captured file to /mnt/sdcard/

  1. private class PreviewHandler extends Handler {
  2. @Override
  3. public void handleMessage(Message msg) {
  4. case SDKEvent.EVENT_FILE_ADDED: {
  5. ICatchFile file = (ICatchFile) msg.obj;
  6. if (file != null) {
  7. fileOperation.downloadFile(file, "/mnt/sdcard/" + file.getFileName());
  8. }
  9. }
  10. /*Other case*/
  11. case xxxx
  12. break;
  13. }

3. Register event listener

  1. fileAddedListener = new FileAddedListener();
  2. cameraAction.addEventListener(
  3. ICatchCamEventID.ICH_CAM_EVENT_FILE_ADDED, fileAddedListener);

4. Unregister event listener

  1. cameraAction.delEventListener(
  2. ICatchCamEventID.ICH_CAM_EVENT_FILE_ADDED, fileAddedListener);

5. The results

shell@m1note:/mnt/sdcard $ ls -l *.JPG
-rw-rw---- root     sdcard_r   642562 2020-04-01 15:07 SA000095.JPG
-rw-rw---- root     sdcard_r   643114 2020-04-01 15:07 SA000096.JPG
-rw-rw---- root     sdcard_r   643250 2020-04-01 15:07 SA000097.JPG
-rw-rw---- root     sdcard_r   642662 2020-04-01 15:07 SA000098.JPG
-rw-rw---- root     sdcard_r   642314 2020-04-01 15:07 SA000099.JPG
-rw-rw---- root     sdcard_r   642373 2020-04-01 15:07 SA000100.JPG

Notes:

  1. Part of the above sample code is not the original Mobilecam API. If you want to find the original API, please click goto definition again.
  2. The Unregister event listener is the last operation and should be removed when you no longer need to pay attention to this event.