Integration with a third party Android app

Android API level 30 and above

It is possible to call Fill and Sign PDF Forms from another Android application by passing it a content uri of the form that should be opened. The following code snippet demonstrates how to do it:

String authority = getString(R.string.app_file_provider);
File   file      = new File(getFilesDir(), "demo.pdf");
Uri    uri       = FileProvider.getUriForFile(this, authority, file);
 
Intent intent = new Intent("biz.binarysolutions.fasp.FILL_AND_SIGN");
intent.setDataAndType(uri, "application/pdf");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("biz.binarysolutions.fasp.ReturnToCaller", true);       // optional, defaults to false
intent.putExtra("biz.binarysolutions.fasp.ActivationCode", "test2222"); // your activation code here
 
intent.setComponent(
    new ComponentName(
        "biz.binarysolutions.fasp",
        "biz.binarysolutions.fasp.Fill"
    )
);
 
startActivityForResult(intent, REQUEST_CODE);

After the form has been filled, depending on the value of ReturnToCaller variable, Fill and Sign PDF Forms app returns either to it’s Select screen (false) or returns to your app (true) providing an output file as a content uri. You can receive the file in your activity in the following way:

@Override
protected void onActivityResult(int request, int result, Intent intent) {
    super.onActivityResult(request, result, intent);
 
    if (request != REQUEST_CODE || result != RESULT_OK || intent == null) {
        return;
    }
 
    String key = "biz.binarysolutions.fasp.PDFOutput";
    Uri    uri = intent.getParcelableExtra(key);
 
    saveUriContent(uri);
}

You can also pre-populate form fields with values that you provide directly from your app. The field names and values are passed as intent extras. The following snippet demonstrates how this is done (it should be inserted between lines 9 and 11 in the first code sample):

intent.putExtra("biz.binarysolutions.fasp.acrofield.fieldName1", "field value 1");
intent.putExtra("biz.binarysolutions.fasp.acrofield.fieldName2", "field value 2");

In case you want to export entered form field values to a JSON file, you should pass the following intent extra (again, it should be inserted between lines 9 and 11 in the first code sample):

intent.putExtra("biz.binarysolutions.fasp.ExportToJSON", true);

In this case JSON content uri can be caught in onActivityResult method the same way the PDF file uri is. For example (insert this between lines 12 and 13 in the second code sample):

key = "biz.binarysolutions.fasp.JSONExport";
uri = intent.getParcelableExtra(key);

JSON file will contain an array of strings, for example:

[ { "fieldName1" : "fieldValue1" }, { "fieldName2" : "fieldValue2" }, ... ]

Where there is a signature field, a “Yes” or “No” value should be returned to identify if a signature has been captured successfully.

You can see the complete integration example on Github here:
https://github.com/binary-solutions/FASPTest

Android API level 29 and bellow

It is possible to call Fill and Sign PDF Forms from another Android application by passing it a full path name of the form that should be opened. The following code snippet demonstrates how to do it:

Intent intent = new Intent("biz.binarysolutions.fasp.FILL_AND_SIGN");
String fileName = "/mnt/sdcard/Download/demo1.pdf";                     // full path name here
intent.putExtra("biz.binarysolutions.fasp.InputFileName", fileName);
intent.putExtra("biz.binarysolutions.fasp.ReturnToCaller", true);       // optional, defaults to false
intent.putExtra("biz.binarysolutions.fasp.ActivationCode", "test2222"); // your activation code here
 
intent.setComponent(
   new ComponentName(
       "biz.binarysolutions.fasp",
       "biz.binarysolutions.fasp.Fill"
   )
);
 
startActivityForResult(intent, REQUEST_CODE);

After the form has been filled, depending on the value of ReturnToCaller variable, Fill and Sign PDF Forms either stays at the Share screen (false) or returns to your app (true) providing an output file name as string. You can receive the file name in your activity in the following way:

@Override
protected void onActivityResult(int request, int result, Intent intent) {
    super.onActivityResult(request, result, intent);
 
    if (request != REQUEST_CODE || result != RESULT_OK || intent == null) {
        return;
    }
 
    String key      = "biz.binarysolutions.fasp.PDFOutput";
    String fileName = intent.getStringExtra(key);
 
    System.out.println(fileName);
}

You can also pre-populate form fields with values that you provide directly from your app. The field names and values are passed as intent extras. The following snippet demonstrates how this is done (it should be inserted between lines 5 and 7 in the first code sample):

intent.putExtra("biz.binarysolutions.fasp.acrofield.fieldName1", "field value 1");
intent.putExtra("biz.binarysolutions.fasp.acrofield.fieldName2", "field value 2");

In case you want to export entered form field values to a JSON file, you should pass the following intent extra (again, it should be inserted between lines 5 and 7 in the first code sample):

intent.putExtra("biz.binarysolutions.fasp.ExportToJSON", true);

In this case JSON file name can be caught in onActivityResult method the same way the PDF file name is. For example (insert this between lines 12 and 13 in the second code sample):

String key2 = "biz.binarysolutions.fasp.JSONExport";
String fileName2 = intent.getStringExtra(key);

JSON file will contain an array of strings, for example:

[ { "fieldName1" : "fieldValue1" }, { "fieldName2" : "fieldValue2" }, ... ]

Where there is a signature field, a “Yes” or “No” value should be returned to identify if a signature has been captured successfully.