Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 true to GiniBank.setCaptureConfiguration(CaptureConfiguration(fileImportEnabled = )). Additionally, your app should declare intent filters for receiving images and/or PDF files from other apps and then forward the incoming intent to Gini Bank SDK.

...

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:

...

Code Block
languagekotlin
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
languagenonekotlin
fun configureCapture() {
  GiniBank.setCaptureConfiguration(this,
    CaptureConfiguration(
      fileImportEnabled = true,
      ... // other configuration options
    )
  )
}

fun startGiniBankSDKForImportedFile(importedFileIntent: Intent) {
    // Use the androidx's Activity Result API to register a handler for the capture result.
val captureImportLauncher = registerForActivityResult(CaptureFlowImportContract()Configure capture first
    configureCapture();

    fileImportCancellationToken =
        GiniBank.createCaptureFlowFragmentForIntent(this /* activity context */, importedFileIntent) { result: CaptureResult ->
            when (result) {
               is CaptureResultGiniBank.CreateCaptureFlowFragmentForIntentResult.SuccessCancelled -> {
            handleExtractions(result.specificExtractions        handleCancellation()
                }
                is CaptureResultGiniBank.CreateCaptureFlowFragmentForIntentResult.Error -> {
            when         handleFileImportError(result.value) {exception)
                }

                is ResultErrorGiniBank.CreateCaptureFlowFragmentForIntentResult.CaptureSuccess -> {
                    val// captureError:Opening GiniCaptureErrorthe = (result.value as ResultError.Capture).giniCaptureError
      file(s) from the intent and creating the CaptureFlowFragment
             handleCaptureError(captureError)       
         }           // Set the listener to receive isthe ResultError.FileImport -> {
  Gini Bank SDK's results
                 val fileImportError = result.value as ResultError.FileImport.fragment.setListener(this)
                    
  handleFileImportError(fileImportError)                 } // Show the CaptureFlowFragment for example via the fragment manager:
  }         }         CaptureResult.Empty -> {requireActivity().supportFragmentManager.beginTransaction()
               handleNoExtractions()         }
 .replace(R.id.fragment_container, result.fragment, "CaptureFlowFragment")
      CaptureResult.Cancel -> {             handleCancellation()   .addToBackStack(null)
     }     } }  fun handleFileImportError(exception: ImportedFileValidationException) {     var message = ...commit()
     exception.validationError?.let { validationError ->        }
// Get the default message        }
message = getString(validationError.textResource)      }
}

// OrHandle the useresults customfrom messagesGini Bank SDK
override fun onFinishedWithResult(result: CaptureResult) {
  message = when (validationErrorresult) {
        is CaptureResult.Success -> {
   FileImportValidator.Error.TYPE_NOT_SUPPORTED -> ...       // Handle extraction results (to  FileImportValidator.Error.SIZE_TOO_LARGE -> ...proceed with the transaction)
            FileImportValidator.Error.TOO_MANY_PDF_PAGES -> ...handleExtractions(result.specificExtractions)
            //  FileImportValidator.Error.PASSWORD_PROTECTED_PDF -> ...
            FileImportValidator.Error.TOO_MANY_DOCUMENT_PAGES -> ...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  AlertDialog.Builder(this)
 approved by the user.
      .setMessage(message)  }
      .setPositiveButton("OK") { _, _is CaptureResult.Error -> finish(){
}         .show() }  funwhen startGiniBankSDKForImportedFile(importedFileIntent: Intent(result.value) {
    // Configure capture first     configureCapture();    is ResultError.Capture 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 java.lang.SecurityException: Permission Denial exceptions when the first activity is finished before the SDK has been launched in the other activity.

Create a Document from the intent in your activity A:

...

languagekotlin

...

 

...

 

...

 

...

     // 

...

There was a capture error
  

...

     

...

      

...

 

...

      val captureError = 

...

result.

...

value as ResultError.Capture
          

...

 

...

 

...

        handleCaptureError(captureError)
    

...

 

...

 

...

          is ResultError.FileImport ->

...

 

...

 

...

 

...

 

...

                // 

...

There was a file import error
                  

...

 

...

 val fileImportError = result.value as ResultError.FileImport
                 

...

 

...

 

...

 

...

handleFileImportError(fileImportError)
            }
        }
       

...

 

...

CaptureResult.

...

Empty -> 

...

{
            // Handle empty result
            

...

handleNoExtractions(

...

)
        }
        CaptureResult.Cancel -> {
  

...

 

...

 

...

 

...

       // Process was cancelled by user
            

...

handleCancellation()
        }
        CaptureResult.EnterManually -> {
        

...

    // User wants to enter the invoice data manually
    

...

        handleEnterManually()
    

...

    }
    

...

Get the Document from the intent extras in your activity B and launch the Gini Bank SDK:

...

languagekotlin

...

}
}

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()
}

Detect when your app is the default app for opening images or PDF files

...