View on GitHub

sensibill-android-documentation

Entry Points

Receipt Capture

The only entry point to this module is via the CaptureStandaloneActivity (See here for the full reference documentation). The Activity optionally takes a CaptureConfig object for configuration as an intent extra, and on result will provide an array of BareCapturedReceiptData objects representing the captured receipt images. For more information about the CaptureConfig object, see the customization entry of the documentation here, or view the class’ reference documentation here

Example:

Below is a simple example outlining the general use case for the standalone capture activity

Kotlin

class MyActivity : AppCompatActivity() {
    // ...

    private fun launchCapture() {
        // Create configuration object if required
        val config = CaptureConfig(
            allowFlashToggling = false,
            defaultFlashMode = FlashMode.FLASH_MODE_OFF,
            maxPages = 5,
            enableLongCapture = false,
            enableSecureWindow = true
        )

        // Create intent and attach config
        val intent = Intent(this, CaptureStandaloneActivity::class.java).apply {
            putExtra(CaptureStandaloneActivity.EXTRA_CAPTURE_CONFIG, config)
        }

        // Start the capture activity
        startActivityForResult(intent, REQUEST_CODE_TO_CAPTURE)
    }

    // ...

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        when (requestCode) {
            REQUEST_CODE_TO_CAPTURE -> {
                // Result is OK when the flow was completed and images were captured
                if (resultCode == Activity.RESULT_OK && data != null) {
                    // Retrieve captured images
                    val capturedImages = data.getSerializableExtra(CaptureStandaloneActivity.EXTRA_CAPTURED_RECEIPTS)
                        as Array<BareCapturedReceiptData>

                    // Process images
                    // ...

                    // *Important* clean up images
                    capturedImages.forEach { it.cleanup() }
                } else {
                    // Capture flow was cancelled
                    Toast.makeText(this, "No images captured", Toast.LENGTH_LONG).show()
                }
            }
            else -> super.onActivityResult(requestCode, resultCode, data)
        }
    }

    // ...

    companion object {
        private const val REQUEST_CODE_TO_CAPTURE = 0x123
    }
}


Java

class MyActivity extends AppCompatActivity {
    private static final int REQUEST_CODE_TO_CAPTURE = 0x123;

    // ...

    private void launchCapture() {
        // Create configuration object if required
        CaptureConfig config = new CaptureConfig(
                false,                      // Allow flash toggling
                FlashMode.FLASH_MODE_OFF,   // Initial flash state
                true,                       // Auto-capture enabled
                true,                       // Initially auto-capture is enabled
                true,                       // Blur detection enabled
                true,                       // Feedback toasts enabled
                true,                       // Gallery import enabled
                true,                       // Multi-page capture is enabled
                5,                          // 5 pages will be captured
                false,                      // Long receipt capture disabled
                true,                       // Crop feature enabled
                true                        // Secure window feature will be enabled
        );

        // Create intent and attach config
        Intent intent = new Intent(this, CaptureStandaloneActivity.class);
        intent.putExtra(CaptureStandaloneActivity.EXTRA_CAPTURE_CONFIG, config);

        // Start the capture activity
        startActivityForResult(intent, REQUEST_CODE_TO_CAPTURE);
    }

    // ...


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        switch (requestCode) {
            case REQUEST_CODE_TO_CAPTURE:
                if (resultCode == Activity.RESULT_OK && data != null) {
                    // Retrieve captured images
                    BareCapturedReceiptData[] capturedImages = (BareCapturedReceiptData[]) data
                            .getSerializableExtra(CaptureStandaloneActivity.EXTRA_CAPTURED_RECEIPTS);

                    // Process images
                    // ...

                    // *Important* clean up images
                    for (BareCapturedReceiptData capturedImage : capturedImages) {
                        capturedImage.cleanup();
                    }
                } else {
                    // Capture flow was cancelled
                    Toast.makeText(this, "No images captured", Toast.LENGTH_LONG).show();
                }
                break;
            default:
                super.onActivityResult(requestCode, resultCode, data);
                break;
        }
    }

    // ...
}