# Android SDK

The Android SDK includes a core native library (closed-source) and a reference UI implementation provided in source code format. This setup allows you to fully customize the UI according to your application’s requirements. While this page provides an overview, you can read more detailed documents at [Android SDK Documentation](https://media.seventhsense.ai/sensecrypt/mobile/3.1.3/android/index.html).  The reference UI is written in Kotlin, however SenseCrypt Android SDK can be used in Java as well.

The Android SDK comes in two variants:

* Online: This variant is small in size, but it needs to connect with the server for SensePrint eID verification/decryption.
* Offline: This variant larger in size, but it can be used to verify/decrypt SensePrint eIDs with no network connectivity and completely on a mobile device.
* OfflineLight: Same as *Offline* but the model files are not included in the SenseCrypt Core AAR (Android Archive) file, but can rather be downloaded during the first initialization of the app.

Both variants utilize the same reference UI implementation.  This means the same Kotlin source code is used for both variants. In the provided Android project you can use the following gradle task to switch between the variants:

```
// to set the project into online mode
./gradlew setSDKmode -Pmode=online

// to set the project into offline mode
./gradlew setSDKmode -Pmode=offline

// to set the project into offlineLight mode
./gradlew setSDKmode -Pmode=offlineLight
```

This gradle task updates the project's dependencies, app name, application id, app icons and changes the Constants for the respective variant. After performing a gradle sync the app can be build in the selected variant.

### Constants

The Constants class contains different app-wide configuration values that can customize the flow of the app. The following are notable constants for customization:

#### Common to both online/offline SDKs

* `GENERATION_CAPTURE_MODE` - the face capture method used while generating a SensePrint. Can be one of `FaceCaptureMode.ActiveCaptureFrontCamera`, `FaceCaptureMode.PassiveCaptureFrontCamera`, or `FaceCaptureMode.PassiveCaptureBackCamera`.
* `VERIFICATION_CAPTURE_MODE` - the face capture method used while verifying a SensePrint. Can be one of `FaceCaptureMode.ActiveCaptureFrontCamera`, `FaceCaptureMode.PassiveCaptureFrontCamera`, or `FaceCaptureMode.PassiveCaptureBackCamera`.  &#x20;
* `SENSEPRINT_VERIFIER_AUTH_KEY` - It is possible to generate SensePrint eID QR codes targeted at a specific verifier. See the section on [Generating your first SensePrint eID QR](https://docs.sensecrypt.com/sensecrypt-v3.1.3/sensecrypt-server/sensecrypt-eid/generating-your-first-senseprint-eid-qr). When the `verifiers_auth_key` attribute is specified while generating the QR, that QR code can only be read by a specific verifier. Set the value of `SENSEPRINT_VERIFIER_AUTH_KEY` to the value you used for `verifiers_auth_key` while generating the QR code. &#x20;
* `SDK_MODE` - whether the current SDK mode is Offline or Online (as changed by the gradle task)
* `DEBUG_FOR_SAVING_IMAGES` - if turned on images are saved to Phone Storage for debug purposes.
* `CONFIG_JSON_FILE_NAME` - Json File to load the config from.

#### Online SDK only

* `API_SERVER_URL` - this value should point to your server that you deployed using the Docker. If you exposed the server using `ngrok` use the Ngrok URL value.&#x20;
* AUTH\_HEADER  - this value should be set to the `mobile_api_key` value you used in the `secrets.json` file while [starting the Docker container](https://docs.sensecrypt.com/sensecrypt-v3.1.3/sensecrypt-server/starting-the-server) for the server. If you are [using a JWT Token for mobile authorization](https://docs.sensecrypt.com/sensecrypt-v3.1.3/sensecrypt-server/using-a-jwt-token-for-mobile-authorization), this should be set to `Bearer your_jwt_token_from_server`

#### Offline SDK only

* `ISSUERS_PUBLIC_KEY` - this value is present only in the offline SDK. If you started the server in Certificate Authority mode by setting the `issuers_private_key`, then the server will issue signed SensePrints. In order to verify them, you must set the corresponding `ISSUERS_PUBLIC_KEY` in the Constants. For more information checkout our [overview](https://docs.sensecrypt.com/sensecrypt-v3.1.3/appendix/signed-and-unsigned-senseprints).
* `LIVENESS_THRESHOLD` - this value defines the threshold of the IDRND liveness check performed on device in offline mode. Default is 0.5.
* `LIVENESS_TOLERANCE` - tolerance of th IDRND liveness. Default is *REGULAR*.
* `LIVENESS_PIPELINE` - IDRND liveness pipeline that should be used. Default is *pegasus*.
* `CUSTOM_MODEL_PATH` - The location to load the models from in *offlineLight.*
* `MODELS_DOWNLOAD_FILE_URLS` - URL to download the models from in *offlineLight.*

### Important Activities

1. **SplashActivity** \
   \
   Responsible for initializing the SDK and loading the necessary Machine Learning models into memory.\
   \
   The SplashActivity culminates by loading the MainActivity. <br>
2. **MainActivity**  \
   \
   A simple interface displaying entry points for SensePrint eID QR generation, verification and reading. Users can interact with buttons to proceed with either operation.<br>
3. **QRScanActivity** \
   \
   This activity can be invoked with or without intent extras. \
   \
   When invoked without any extras, the activity will interpret the launch as an attempt to capture QR data that will subsequently be decrypted via a face scan. \
   \
   Based on the capture type which is set up in `Constants.kt` configuration, after scanning a QR code (when invoked without intent data), the app will proceed to `PreScanningActiveCaptureActivity` activity for Active Face Capture or  `PreScanningPassiveCaptureActivity`for Passive Face Capture.\
   \
   When the `QRScanActivity` is invoked with an extra, the activity will attempt to read the non-face-encrypted regions of a SensePrint eID QR code and show that data by passing it in an intent and launching the `ReaderDetailActivity`.<br>
4. **ActiveFaceCaptureActivity** \
   \
   This activity may be invoked with or without intent extras. \
   \
   When invoked with an extra containing the SensePrint bytes (from the `QRScanActivity`), the activity will attempt to decrypt the SensePrint bytes and pass the metadata along to the `PersonDetailActivity`.\
   \
   When invoked without any extras, the activity will pass the captured image via an intent by launching the `GenerateQRActivity`.<br>
5. **PassiveFaceCaptureActivity** \
   \
   This activity works in exactly the same way as the `ActiveFaceCaptureActivity`. The only difference is that it captures a single good image from the session.<br>
6. **ReaderDetailActivity** \
   \
   This activity gets clear text data (non-face encrypted) in an intent and displays it on the screen for viewing.<br>
7. **PersonDetailActivity** \
   \
   This activity shows the eID attributes that are passed to it via an intent extra.<br>
8. **GenerateQRActivity** \
   \
   When invoked from the `ActiveFaceCaptureActivity` or `PassiveFaceCaptureActivity`, this activity prompts for input of eID attributes such as name, ID etc.\
   \
   Upon accepting the input, the activity invokes the `ShowQRActivity` to show the generated QR code.<br>
9. **ShowQRActivity** \
   \
   This activity accepts QR code bytes as an intent extra, and shows a generated QR code containing those bytes on the screen.

### Additional Notes

The SDK is designed for modularity, allowing full customization of the user interface and integration flows while maintaining core functionality within a closed-source native library.

This document serves as a guide to understand and integrate the Android SDK into your application. Be sure to configure the constants accurately to align with your deployment setup and security requirements.
