Page Properties | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
|
...
We use the term file import
to refer to the Open with feature within Gini Bank SDK. From the point of view of the SDK, files are imported into the SDK from an outside source. It is unaware and can't set configuration related to enabling the client app to receive files via Android’s Open-with or /Share functionality.
...
The “Open with…” feature can be found under different names in the Android phones, e.g: "Send to", "Share", “Share with” and "Open with".
Note |
---|
Please note that the “Open with (Share, Send to)” feature is disabled by default. To enable this feature, pass |
...
Register image and PDF file types
Note |
---|
Make sure the name of activity used in the below configuration is the same as the name of the activity handling your SDK implementation. In addition: Make sure that this activity is publically available. |
Add the following intent filter to the activity in your AndroidManifest.xml
to receive incoming images and PDF files:
...
We recommend adding ACTION_VIEW to the intent filter to let users send images and PDF files to your app from apps that don’t implement sharing with ACTION_SEND but enable viewing images and PDF files with other apps.
Handle imported files
When your app is requested to handle an image or a PDF file, your activity (declaring the intent filter shown above) is launched or resumed (onNewetentonNewIntent()
) with the Intent
having ACTION_VIEW
or ACTION_SEND
.
...
Code Block | ||
---|---|---|
| ||
String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SEND.equals(action)) { ... } |
Launch the SDK as a fragment
If the Intent
passes the above check then register an activity result handler with the CaptureFlowImportContract()
and check for ACTION_VIEW and ACTION_SEND, then pass the Intent
to GiniBank.startCaptureFlowFortentcreateCaptureFlowFragmentForIntent()
:
Code Block | ||
---|---|---|
| ||
fun configureCapture() { GiniBank.setCaptureConfiguration(this, CaptureConfiguration( fileImportEnabled = true, ... // other configuration options ) ) } fun startGiniBankSDKForImportedFile(importedFileIntent: Intent) { // Configure capture first configureCapture(); fileImportCancellationToken = GiniBank.createCaptureFlowFragmentForIntent(this /* activity context */ Use the androidx's Activity Result API to register a handler for the capture result. val captureImportLauncher = registerForActivityResult(CaptureFlowImportContract()) { result: CaptureResult ->, importedFileIntent) { result -> when (result) { GiniBank.CreateCaptureFlowFragmentForIntentResult.Cancelled -> { handleCancellation() } is GiniBank.CreateCaptureFlowFragmentForIntentResult.Error -> { handleFileImportError(result.exception) } is GiniBank.CreateCaptureFlowFragmentForIntentResult.Success -> { // Opening the file(s) from the intent and creating the CaptureFlowFragment // Set the listener to receive the Gini Bank SDK's results result.fragment.setListener(this) // Show the CaptureFlowFragment for example via the fragment manager: requireActivity().supportFragmentManager.beginTransaction() .replace(R.id.fragment_container, result.fragment, "CaptureFlowFragment") .addToBackStack(null) .commit() } } } } // Handle the results from Gini Bank SDK override fun onFinishedWithResult(result: CaptureResult) { when (result) { is CaptureResult.Success -> { // Handle extraction results (to proceed with the transaction) handleExtractions(result.specificExtractions) // After the user has seen (and maybe edited) the extractions and has executed the transfer // please send the transfer summary to Gini with the final data approved by the user. } is CaptureResult.Error -> { when (result.value) { is ResultError.Capture -> { // There was a capture error val captureError: GiniCaptureError = (result.value as ResultError.Capture).giniCaptureError handleCaptureError(captureError) is ResultError.FileImport -> } // There was isa ResultError.FileImport -> {file import error val fileImportError = result.value as ResultError.FileImport handleFileImportError(fileImportError) } } CaptureResult.Empty -> { // Handle empty result }handleNoExtractions() } CaptureResult.EmptyCancel -> { // Process was cancelled by user handleNoExtractions handleCancellation() } CaptureResult.CancelEnterManually -> { // User wants to enter the invoice data manually handleCancellation handleEnterManually() } } } fun handleFileImportError(exception: ImportedFileValidationException) { var message = ... exception.validationError?.let { validationError -> // Get the default message message = getString(validationError.textResource) // Or use custom messages message = when (validationError) { FileImportValidator.Error.TYPE_NOT_SUPPORTED -> ... FileImportValidator.Error.SIZE_TOO_LARGE -> ... FileImportValidator.Error.TOO_MANY_PDF_PAGES -> ... FileImportValidator.Error.PASSWORD_PROTECTED_PDF -> ... FileImportValidator.Error.TOO_MANY_DOCUMENT_PAGES -> ... } } AlertDialog.Builder(this) .setMessage(message) .setPositiveButton("OK") { _, _ -> finish() } .show() } fun startGiniBankSDKForImportedFile(importedFileIntent: Intent) { // Configure capture first configureCapture(); fileImportCancellationToken = GiniBank.startCaptureFlowForIntent(captureImportLauncher, this, importedFileIntent) } |
...
Detect when your app is the default app for opening images or PDF files
...
It is easy for Android users to can unintentionally set your app as the default for opening PDFs images or imagesPDF files. To inform users about it and allow let them to undo it, the SDK detects if your app was is selected as the default app and shows the Clear Defaults Dialog to inform users and to enable enabling them to clear the defaults for your app in the Android settings.
...