Prerequisites
- Nosmai Effects installed for Android
- Android API 24 or later, compile SDK 35, and Java 11
- A physical device whose ABI list contains
arm64-v8aorarmeabi-v7a - 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 enable OES input:
FrameLayout container = findViewById(R.id.preview_container); NosmaiPreviewView previewView = new NosmaiPreviewView(this); container.addView(previewView); previewView.enableOesInput(true);
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:
NosmaiPreviewView.OnOesReadyListener oesReady = surfaceTexture -> {
camera2Source.openFrontCamera(surfaceTexture);
};
previewView.addOnOesReadyListener(oesReady);
Use the public NosmaiPreviewView.OnOesReadyListener type explicitly. This selects the public overload without an ambiguous Java lambda or an internal listener import.
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
Register beauty setup before starting processing. It runs after the pipeline is ready:
previewView.addOnPipelineReady(() -> {
NosmaiBeauty.applySkinSmoothing(0.4f);
});
NosmaiSDK.startProcessing(previewView);
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();
}
Call previewView.onResume() from the matching Activity or Fragment resume callback. The app's Camera2 owner must also reopen its capture session against the current valid OES surface; resuming the view alone does not reopen a camera that the app closed. Serialize close and reopen operations and ignore readiness callbacks for a camera screen that has already been disposed.
Run the screen on a physical arm64-v8a or armeabi-v7a device. The full application structure, Camera2 helper, orientation handling, and OES fallback are demonstrated in the Android WebRTC example. For external-frame setup and orientation, follow the custom frame pipeline guide.
Verify it worked
You should see the front-camera preview and a visible smoothing change at level 0.4. Any on-screen status label is part of your application's UI, not created by these snippets. 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 both supported ABIs | Use a physical Android device with arm64-v8a or armeabi-v7a |
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