# Android quickstart

> Initialize Nosmai Effects, connect your Camera2 source, show the processed preview, and apply a beauty effect on Android.

> For AI agents: the complete documentation index is at https://nosmai.com/llms/effects.txt

Product: Nosmai Effects
Group: get-started
Source: https://nosmai.com/docs/effects/quickstart/android/

## Prerequisites

- [Nosmai Effects installed for Android](/docs/effects/installation/android/)
- Android API 21 or later, compile SDK 35, and Java 11
- A physical device whose ABI list contains `arm64-v8a`
- A [Nosmai licence key](/docs/effects/license-key/) bound to the application ID
- `CAMERA` and `INTERNET` permissions in `AndroidManifest.xml`

## 1. Add manifest permissions

```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
```

## 2. Initialize Nosmai once

Initialize from the application owner after loading the app-specific key:

```java
NosmaiSDK.initialize(
    getApplicationContext(),
    BuildConfig.NOSMAI_LICENSE_KEY
);
```

Do not initialize from every activity or fragment. Continue only after camera
permission is granted.

## 3. Add the preview

Add a container to the camera screen:

```xml
<FrameLayout
    android:id="@+id/preview_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
```

Create one `NosmaiPreviewView` for that container and start processing:

```java
FrameLayout container = findViewById(R.id.preview_container);
NosmaiPreviewView previewView = new NosmaiPreviewView(this);

container.addView(previewView);
previewView.enableOesInput(true);
NosmaiSDK.startProcessing(previewView);
```

## 4. Connect the Camera2 source

The Android SDK accepts Camera2 frames from the host application. Connect the
front-camera capture session to the OES texture supplied by the preview:

```java
previewView.addOnOesReadyListener(surfaceTexture -> {
    camera2Source.openFrontCamera(surfaceTexture);
});
```

`camera2Source` is the application's Camera2 owner. It must select a preview
size, set sensor orientation, start one repeating capture request, and close the
camera when the screen pauses. Reuse an existing camera component when the app
already has one. Keep the Nosmai and regular camera sessions from owning the
device at the same time.

## 5. Apply the first effect

Apply beauty after the processing pipeline is ready:

```java
previewView.addOnPipelineReady(() -> {
    NosmaiBeauty.applySkinSmoothing(0.4f);
});
```

## 6. Release the camera

Close the Camera2 session before pausing the preview. Stop Nosmai processing
when the camera screen is destroyed:

```java
@Override
protected void onPause() {
    camera2Source.close();
    previewView.onPause();
    super.onPause();
}

@Override
protected void onDestroy() {
    NosmaiSDK.stopProcessing();
    super.onDestroy();
}
```

Run the screen on a physical `arm64-v8a` device. The full application structure,
Camera2 helper, orientation handling, and OES fallback belong in the sample
project rather than this quickstart.

## Verify it worked

You should see the front-camera preview, the status `Camera ready with skin
smoothing`, and a visible smoothing change at level `0.4`. Move the app to the
background and confirm the camera indicator turns off. Return and confirm the
same preview resumes.

## Common errors

| Error | Cause | Fix |
| --- | --- | --- |
| `License key cannot be null or empty` | Android received an empty key | Supply an app-bound key before calling `NosmaiSDK.initialize` |
| `Preview view cannot be null` | `startProcessing` was called without a preview instance | Create `NosmaiPreviewView` and pass that instance |
| `Nosmai SDK is not initialized. Call NosmaiSDK.initialize() first.` | Processing started before initialization | Initialize once before calling `startProcessing` |
| `Camera device error: 2` | Camera2 reported `ERROR_CAMERA_IN_USE`, usually because another controller still owns the camera | Stop and dispose the other camera before opening Nosmai |
| `INSTALL_FAILED_NO_MATCHING_ABIS` | Device lacks `arm64-v8a` | Use a physical ARM64 Android device |

## Next steps

- [Apply a beauty filter on Android](/docs/effects/guides/effects/apply-a-beauty-filter/android/)
- [Replace the background in Android](/docs/effects/guides/background/replace-the-background/android/)
- [Download a Cloud Filter in Android](/docs/effects/guides/filters/download-a-cloud-filter/android/)
- [Render processed frames for streaming in Android](/docs/effects/guides/streaming/render-frames-off-screen/android/)

## References

- [Android installation](/docs/effects/installation/android/)
- [Android release repository](https://github.com/nosmai/nosmai_effects_sdk_android)
- [How the pipeline works](/docs/effects/concepts/how-the-pipeline-works/)
- [Nosmai Effects](https://nosmai.com/effects/)
- [Nosmai Effects pricing](https://nosmai.com/effects/#pricing)
