Prerequisites
- Nosmai Effects installed for 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 bound to the application ID
CAMERAandINTERNETpermissions inAndroidManifest.xml
1. Add manifest permissions
<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:
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:
<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:
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:
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:
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:
@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
- Replace the background in Android
- Download a Cloud Filter in Android
- Render processed frames for streaming in Android