Android Paper Integration
1. Implement RecognizerCallback
RecognizerCallback delivers scan results and error events:
public interface RecognizerCallback {
// Called when scanning is complete and results are ready.
void onRecognizerDone(@NonNull ScanResults results, Media media);
// Called if an exception occurs while processing a frame.
void onRecognizerException(@NonNull Throwable e);
// Called each time an intermediate result is produced during scanning.
void onRecognizerResultsChanged(@NonNull RecognizerResult result);
}
Intermediate Result Types
onRecognizerResultsChanged fires throughout the scan session. Cast the RecognizerResult to the specific type you need:
Preliminary results — partial data before the scan ends:
@Override
public void onRecognizerResultsChanged(@NonNull RecognizerResult result) {
if (result instanceof PreliminaryResult) {
PreliminaryResult preliminary = (PreliminaryResult) result;
// Use partial receipt data
}
}
Raw OCR results:
@Override
public void onRecognizerResultsChanged(@NonNull RecognizerResult result) {
if (result instanceof OcrRawResult) {
OcrRawResult ocrRawResult = (OcrRawResult) result;
}
}
Edge detection results — frame quality feedback:
@Override
public void onRecognizerResultsChanged(@NonNull RecognizerResult result) {
if (result instanceof EdgeDetectionResult) {
EdgeDetectionResult edges = (EdgeDetectionResult) result;
// edges.contentPercent — how much of the frame the receipt fills
// edges.state — ABOVE_THRESHOLD, BELOW_THRESHOLD, etc.
}
}
Edge detection states:
| State | Meaning |
|---|---|
ABOVE_THRESHOLD | Receipt fills at least the configured minimum percentage of the frame |
BELOW_THRESHOLD | Receipt is too small in the frame |
CONSECUTIVE_ABOVE_THRESHOLD_LIMIT_REACHED | N consecutive frames above threshold — ready to capture |
CONSECUTIVE_BELOW_THRESHOLD_LIMIT_REACHED | N consecutive frames below threshold |
Camera Callback
If you are using RecognizerView (custom UI), also implement CameraRecognizerCallback:
public interface CameraRecognizerCallback {
// Called when a captured frame is saved to disk.
void onConfirmPicture(@NonNull File file);
// Called when camera permission is denied.
void onPermissionDenied();
void onPreviewStarted();
void onPreviewStopped();
void onException(@NonNull Throwable throwable);
}
2. RecognizerView (Custom Camera UI)
RecognizerView gives you a camera preview surface you can embed in any layout. It manages its own internal state, but you must forward activity lifecycle events to it:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recognizerView.create();
}
@Override
public void onStart() {
super.onStart();
recognizerView.start();
}
@Override
public void onResume() {
super.onResume();
recognizerView.resume();
}
@Override
public void onPause() {
super.onPause();
recognizerView.pause();
}
@Override
public void onStop() {
super.onStop();
recognizerView.stop();
}
@Override
public void onDestroy() {
super.onDestroy();
recognizerView.destroy();
}
Initializing the View
Before use, call initialize(ScanOptions scanOptions) with your scan configuration.
Capturing Frames
recognizerView.takePicture(cameraCaptureListener);
The listener receives a BitmapResult. Once the user confirms the frame:
recognizerView.confirmPicture(bitmapResult);
Confirmed frames are written to disk and returned via the Media object in onRecognizerDone.
Finishing a Scan
recognizerView.finishedScanning();
This compiles and finalizes results, delivering them through onRecognizerDone(ScanResults results, Media media). All RecognizerCallback methods are invoked on the main thread.
To cancel mid-scan:
recognizerView.terminate();
3. AndroidManifest Keys
Add optional service keys to AndroidManifest.xml inside the <application> element:
Product Intelligence — enriches receipt line items with product data:
<meta-data
android:name="com.microblink.ProductIntelligence"
android:value="YOUR_PRODUCT_INTELLIGENCE_KEY" />
Google Places — merchant location enrichment:
<meta-data
android:name="com.microblink.GooglePlacesKey"
android:value="YOUR_GOOGLE_PLACES_KEY" />
Yelp — merchant data enrichment:
<meta-data
android:name="com.microblink.YelpKey"
android:value="YOUR_YELP_KEY" />
Client User ID — associates scan sessions with your user identifiers:
<meta-data
android:name="com.microblink.ClientUserId"
android:value="YOUR_CLIENT_USER_ID" />