Native Module Android
How to Create a Native Module in Android
This detailed guide explains how to create a native module for the Android platform within a React Native application. The process follows the step-by-step instructions from the official documentation.
1. Open the Android Project in Android Studio
First, open the Android project of your React Native application in Android Studio. You can find the Android project in the folder: YourApp/android.
Using Android Studio helps in quickly identifying issues, such as syntax errors, and provides powerful tools for Android development.
2. Create the Native Module
Create a file named CafSmartAuthBridgeModule.kt in the directory android/app/src/main/java/com/your-app-name/. This file will contain the class that implements the native module.
Key Functions of the CafSmartAuthBridgeModule Class
getName: This function returns the name of the native module, which will be used to access it in JavaScript within React Native. The name must be unique to avoid conflicts with other modules.build: Thebuildfunction is responsible for configuring and instantiating theCafSmartAuthobject using the provided parameters. This function applies various settings, such as defining stages and facial authentication, to prepare the SDK for use.emitEvent: Allows sending events from the native side to JavaScript. Events can include success, errors, or other relevant statuses.setupListener: Sets up a listener to monitor the status of verification operations, such as success, pending, error, cancellation, and others.requestPermission: Requests the necessary permissions, such as location permissions, for the proper functioning of the SDK.startSmartAuth: Exposed to JavaScript, this function starts the smart authentication process using the received parameters.requestLocationPermissions: Exposed to JavaScript, allows the application to request location permissions from the user.
Example Implementation of the CafSmartAuthBridgeModule.kt File
3. Create the CafSmartAuthBridgeSettings.kt File
This file will handle the interpretation of data sent from React Native to the native module.
Example Implementation:
4. Register the Native Module
To make the native module recognizable by React Native, create a file named CafPackage.kt in the same directory:
Example Implementation:
In the MainApplication.kt file, add the CafPackage module inside the getPackages method:
Example Implementation:
With this, your native module is configured and ready to be used in React Native.
Last updated

