...
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
Add the following intent filter to the activity in your AndroidManifest.xml
to receive incoming images and PDF files:
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:
Code Block | ||
---|---|---|
| ||
<activity android:name=".ui.MyActivity"> <!-- Receiving images: --> <intent-filter android:label="@string/label_for_image_open_with"> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.SEND" /> <!-- The below SEND_MULTIPLE action is only needed if you enabled scanning of multi-page documents: --> <action android:name="android.intent.action.SEND_MULTIPLE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> <!-- Receiving pdfs: --> <intent-filter android:label="@string/label_for_pdf_open_with"> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/pdf" /> </intent-filter> </activity> |
...
Code Block | ||
---|---|---|
| ||
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SEND.equals(action)) {
...
} |
Launch the SDK as an activity
If the Intent
passes the above check then register an activity result handler with the CaptureFlowImportContract()
and pass the Intent
to GiniBank.startCaptureFlowForIntent()
:
Code Block | ||
---|---|---|
| ||
fun configureCapture() {
GiniBank.setCaptureConfiguration(this,
CaptureConfiguration(
fileImportEnabled = true,
... // other configuration options
)
)
}
// Use the androidx's Activity Result API to register a handler for the capture result.
val captureImportLauncher = registerForActivityResult(CaptureFlowImportContract()) { result: CaptureResult ->
when (result) {
is CaptureResult.Success -> {
handleExtractions(result.specificExtractions)
}
is CaptureResult.Error -> {
when (result.value) {
is ResultError.Capture -> {
val captureError: GiniCaptureError = (result.value as ResultError.Capture).giniCaptureError
handleCaptureError(captureError)
}
is ResultError.FileImport -> {
val fileImportError = result.value as ResultError.FileImport
handleFileImportError(fileImportError)
}
}
}
CaptureResult.Empty -> {
handleNoExtractions()
}
CaptureResult.Cancel -> {
handleCancellation()
}
}
}
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)
} |
Launch the SDK from a different activity
When your activity (declaring the intent filter shown above) is not the same as the activity from which you launch the Gini Bank SDK you need to create a Document
from the intent first and then pass it to your other activity as an extra. There you can then launch the SDK with the Document
.
Note |
---|
Passing the launch intent from the first activity to the other activity causes |
Create a
Document
from the intent in your activity A:Code Block language kotlin fun createDocumentAndLaunchActivityB(importedFilesIntent: Intent) { // Configure capture first configureCapture(); fileImportCancellationToken = GiniBank.createDocumentForImportedFiles( intent = intent, context = this, callback = { documentCreationResult -> when (documentCreationResult) { GiniBank.CreateDocumentFromImportedFileResult.Cancelled -> showCancellationToast("'Open with' cancelled") is GiniBank.CreateDocumentFromImportedFileResult.Error -> showErrorToast("'Open with' failed with error ${documentCreationResult.error}") is GiniBank.CreateDocumentFromImportedFileResult.Success -> documentCreationResult.document?.let { document -> launchActivityB(document) } ?: run { showErrorToast("'Open with' failed") } } } ) }
Get the Document
from the intent extras in your activity B and launch the Gini Bank SDK:
...
language | kotlin |
---|
...
} |
Launch the SDK as a fragment
...