> For the complete documentation index, see [llms.txt](https://doc.faceplugin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.faceplugin.com/products/face-recognition-sdk/liveness-detection-sdk/mobile-sdk/liveness-detection-android-sdk.md).

# Android

Faceplugin Face Liveness Detection Android SDK. On-premise PAD against photos, screens, masks, and deepfakes. AAR, setActivation, init, faceDetection, detect.

Fully on-premise **Face Liveness SDK for Android** (presentation-attack detection). The demo does not enroll people or run 1:N search. It scores whether the face is real.

| What                      | Id                                               |
| ------------------------- | ------------------------------------------------ |
| Android demo package name | `com.faceplugin.faceliveness`                    |
| Public Java class         | `com.faceplugin.facelivenesssdk.FaceLivenessSDK` |

Keep the demo package name **`com.faceplugin.faceliveness`** so the sample key works.

### Code <a href="#setup" id="setup"></a>

{% embed url="<https://github.com/Faceplugin-ltd/FaceLivenessDetection-Android>" %}

### Setup <a href="#setup" id="setup"></a>

1. Copy the SDK (`libfacesdk` folder) to the `root` folder in your project. Place `facelivenessdk.aar` from [Google Drive](https://drive.google.com/drive/folders/1x3jt02f-YHsk4WD_QlnKJSx5uQ5Ds4xH) inside `libfacesdk/`.
2. Add SDK to the project in `settings.gradle`

```
rootProject.name = "YourProjectName"
include ':app'
include ':libfacesdk'
```

3. Add dependency to your `build.gradle`

```
implementation project(path: ':libfacesdk')
```

4. minSdk **24**, `useLegacyPackaging = true`, CAMERA permission. Call **setActivation → init** on a **background** thread.

Status codes: **0** Success, **1** Invalid license, **2** Expired, **3** Not activated, **4** Init failed.

### APIs

#### <mark style="color:orange;">setActivation:</mark> This API is used to activate the SDK <a href="#setactivation" id="setactivation"></a>

```java
public static int setActivation(Context context, String license);
```

| **Input**        | <ul><li><strong>context</strong> (Context): Android <code>Context</code></li><li><strong>license</strong> (String): The license string (<code>license key</code>)</li></ul> |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Return value** | <p>The SDK activation status code.</p><ul><li>0: Success</li><li>1: Invalid license</li><li>2: Expired</li><li>3: Not activated</li><li>4: Init failed</li></ul>            |

#### <mark style="color:orange;">init:</mark> This API is used to initialize the SDK <a href="#init" id="init"></a>

```java
public static int init(Context context) throws IOException;
```

#### <mark style="color:orange;">getMachineCode:</mark> This API is used to retrieve the machine code <a href="#getmachinecode" id="getmachinecode"></a>

```java
public static String getMachineCode(Context context);
```

#### <mark style="color:orange;">getLicenseStatus:</mark> This API is used to read license status <a href="#getlicensestatus" id="getlicensestatus"></a>

```java
public static String getLicenseStatus();
public static boolean allowsLiveness();
public static String lastEngineError();
```

Use `allowsLiveness()` before Capture.

#### <mark style="color:orange;">faceDetection:</mark> This API is used to detect faces and determine if the faces are real or fake <a href="#facedetection" id="facedetection"></a>

```java
public static List<FaceBox> faceDetection(Bitmap bitmap, FaceDetectionParam param);
```

| **Input**        | <ul><li><strong>bitmap</strong> (Bitmap): The Bitmap image</li><li><strong>param</strong> (<strong>FaceDetectionParam</strong>): Parameters for face detection</li></ul> |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Return value** | A list of **FaceBox** objects representing the detected faces and their liveness scores.                                                                                 |

**FaceDetectionParam**

```java
public class FaceDetectionParam {
    public boolean check_liveness = false; // set it to true to check liveness
    public int check_liveness_level = 0; // 0: accurate model, 1: light model
    public boolean check_eye_closeness = false;
    public boolean check_face_occlusion = false;
    public boolean check_pose = true;
    public boolean check_landmarks = true;
    public boolean check_quality = false;
}
```

**FaceBox**

```java
public class FaceBox {
    public int x1, y1, x2, y2;
    public float liveness, yaw, roll, pitch;
    public float face_quality, face_luminance, score;
    public int trackId;
    public String livenessLabel;
}
```

The liveness score ranges from 0.0 to 1.0. If it's greater than the threshold, it's real face. Demo default threshold is **0.5**.

#### <mark style="color:orange;">detect:</mark> This API is used to detect faces and return engine JSON <a href="#detect" id="detect"></a>

```java
public static String detect(Bitmap bitmap, boolean crop, int flags);
```

`detect` requires a liveness-capable license.

#### <mark style="color:orange;">VideoWorker:</mark> This API is used for the live camera HUD <a href="#videoworker" id="videoworker"></a>

The demo does **not** enroll. VideoWorker match DB is empty. Use it to keep a live track while you still score with `faceDetection`:

`startVideoWorker` → `addVideoWorkerFrame` → `stopVideoWorker`.

#### <mark style="color:orange;">deinit:</mark> This API is used to unload the engine <a href="#deinit" id="deinit"></a>

```java
public static int deinit();
```

### Run the demo

1. Place `facelivenessdk.aar` in `libfacesdk/` (see Setup).
2. Keep the demo package name **`com.faceplugin.faceliveness`**.
3. Run on a **physical** phone.
4. Home tiles: **Liveness**, Settings, About. The demo does **not** enroll people or run 1:N search.

### Screenshots

| Home                                                                                                                                                                                           | Liveness                                                                                                                                                                                          | Settings                                                                                                                                                                                       | About                                                                                                                                                                                    |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://raw.githubusercontent.com/Faceplugin-ltd/faceplugin-assets/main/screenshots/face-liveness/mobile/home.png" alt="Faceplugin Face Liveness Android home" data-size="original"> | <img src="https://raw.githubusercontent.com/Faceplugin-ltd/faceplugin-assets/main/screenshots/face-liveness/mobile/liveness.png" alt="Faceplugin Face Liveness live camera" data-size="original"> | <img src="https://raw.githubusercontent.com/Faceplugin-ltd/faceplugin-assets/main/screenshots/face-liveness/mobile/settings.png" alt="Faceplugin Face Liveness settings" data-size="original"> | <img src="https://raw.githubusercontent.com/Faceplugin-ltd/faceplugin-assets/main/screenshots/face-liveness/mobile/about.png" alt="Faceplugin Face Liveness About" data-size="original"> |

### License

Licenses are **offline**. Request a new license key for your own app. Use `allowsLiveness()` before Capture.

{% hint style="warning" %}
`FaceDetectionParam.check_liveness` defaults to **false**. Set it to **true** or you will not get a liveness score.
{% endhint %}

### Try it (after the demo compiles)

```java
FaceDetectionParam param = new FaceDetectionParam();
param.check_liveness = true;
param.check_liveness_level = 0; // 0 accurate, 1 light
List<FaceBox> faces = FaceLivenessSDK.faceDetection(bitmap, param);
if (!faces.isEmpty() && faces.get(0).liveness >= 0.5f) {
    // Real
}
```

[Request a License & Support](/help/request-a-license-and-support.md) · [Contact us](/help/contact-us.md)

### FAQ

**Passive or active?** **Passive** anti-spoofing. Score the camera frame; no smile / turn-head challenge on this product.

**Threshold?** Treat **0.5** or higher as Real / pass unless Faceplugin support gives you a different recommended threshold.

### Related documentation

* [Faceplugin Face Liveness Detection Mobile SDK](/products/face-recognition-sdk/liveness-detection-sdk/mobile-sdk.md) · [iOS](/products/face-recognition-sdk/liveness-detection-sdk/mobile-sdk/liveness-detection-ios-sdk.md) · [Glossary](/help/resources/glossary.md)
* [Face Recognition Android SDK](/products/face-recognition-sdk/recognition-and-liveness/mobile-sdk/face-recognition-android-sdk.md)
* [ID Document Recognition Android SDK](/products/id-document-recognition-sdk/recognition-and-liveness/mobile-sdk/id-document-recognition-android-sdk.md)
* [Request a License](/help/request-a-license-and-support.md) · [Status codes](/help/resources/status-codes.md)
* [Combining products (eKYC)](/getting-started/choose-a-product.md) · [SDK comparison](/help/comparisons.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.faceplugin.com/products/face-recognition-sdk/liveness-detection-sdk/mobile-sdk/liveness-detection-android-sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
