How to Implement Multipage Image Capture with User Interface
Note: Before you begin, see Build your application with the library for Android.
Below you can find description of a basic image capture scenario with user interface components.
- Before you start, add the CaptureView class to the XML layout of your Activity or Fragment with default parameters. If you are implementing a non-English app, you can override the string resources of the user interface, using the attributes' IDs (see CaptureView attributes for details).
Note: Please make sure, that you are using the Theme.AppCompat theme. Multipage image capture scenario requires this theme for user interface implementation.
- Receive the CaptureView class object from your layout inside the onCreate Activity or onViewCreated Fragment.
- Override the onResume and onPause methods, embedding the UI components methods:
- Call the Engine.load method on the UI thread to create an engine object, required for all recognition mechanisms to work. This object should be reused for every new operation and should not be created again in the same application.
- Create a Builder class object. Via this object the MultiPageImageCaptureScenario object will be created on the next step. Pass to the Builder the created Engine object and Context. Passing Context to the constructor will set a default internal path for image files storage.
- The Builder class object provides various methods for flexible tuning of your application. I.e., depending on your application goal you can tune the presets of the scenario user interface and image count requirements:
- use the setRequiredPageCount method of the Builder object for fixing an exact number of images to be captured or allow unlimited image capture;
- to customize interface string resources, do the following:
- When the Builder class object is tuned, create the MultiPageImageCaptureScenario object via the build method.
- Implement the Callback interface. The methods of the callback will be used to get the result and monitor errors. Here are brief recommendations on what the methods should do:
- the onFinished method returns Result object, which methods for provide access to the captured images and corresponding metadata;
- the onClose method is for capture scenario should be stopped by user;
- the onError method is for handling errors.
- Use the CaptureView.setCaptureScenario method to set the image capture scenario.
- The scenario is started automatically by default. You may delay it with stop method and then start it with start method. If you want to delay the start, use the MultiPageImageCaptureScenario.stop method to stop the automatically started scenario and then start it with MultiPageImageCaptureScenario.start method.
- Wait for the response or an error in the callback. If scenario is stopped by user on tapping "Cancel", onClose method will be called. If "Done" button was tapped, onFinished method will be called.
See the description of classes and methods in the User Interface API Reference section.