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
// in file type/ICatchCamEvent.javaICatchCamEventID.ICH_CAM_EVENT_FILE_ADDED
For c++ API
// in file type/ICatchCamEventID.htypedef enum ICatchCamEventID {ICH_CAM_EVENT_FILE_ADDED = 0x01,....}
Event parameters and usage
Get the newly added file object through
getFileValue1 ()of theICatchCamEventobject.For java API
public class FileAddedListener implements ICatchCameraListener {@Overridepublic void eventNotify(ICatchCamEvent arg0) {// The arg0.getFileValue1() returns the valid file object, see following code.handler.obtainMessage(EVENT_FILE_ADDED, arg0.getFileValue1()).sendToTarget();}}
For C++ API
class FileAddedListener : public ICatchCameraListener{public:void eventNotify(shared_ptr<ICatchCamEvent> arg0) {// The arg0.getFileValue1() returns the valid file object, see following code.auto file = arg0->getFileValue1();printf("The newly added file, path: %s, name: %s\n",file->getFilePath().c_str(), file->getFileName().c_str());}}
Example:
1. Create EventListener class
public class FileAddedListener implements ICatchCameraListener {@Overridepublic void eventNotify(ICatchCamEvent arg0) {handler.obtainMessage(EVENT_FILE_ADDED, arg0.getFileValue1()).sendToTarget();}}
2. Handler‘s handleMessage callback. We save the captured file to /mnt/sdcard/
private class PreviewHandler extends Handler {@Overridepublic void handleMessage(Message msg) {case SDKEvent.EVENT_FILE_ADDED: {ICatchFile file = (ICatchFile) msg.obj;if (file != null) {fileOperation.downloadFile(file, "/mnt/sdcard/" + file.getFileName());}}/*Other case*/case xxxxbreak;}
3. Register event listener
fileAddedListener = new FileAddedListener();cameraAction.addEventListener(ICatchCamEventID.ICH_CAM_EVENT_FILE_ADDED, fileAddedListener);
4. Unregister event listener
cameraAction.delEventListener(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:
- Part of the above sample code is not the original Mobilecam API. If you want to find the original API, please click
goto definitionagain. - The Unregister event listener is the last operation and should be removed when you no longer need to pay attention to this event.
