This is a React Native application that integrates a WebView to load the GlamAR SDK. The WebView requests camera permissions and interacts with the SDK for skin analysis and other AR-based functionalities.
- Loads GlamAR SDK inside a WebView
- Requests camera permissions on Android
- Handles WebView messages to track events
- Sends initialization data to the SDK
root
├── App.tsx # Main entry point of the app
├── android/
│ ├── app/
│ │ ├── src/
│ │ │ ├── main/
│ │ │ │ ├── java/com/glam/MainActivity.java # Handles WebView permissions
│ │ │ │ ├── AndroidManifest.xml # Permissions configuration
│ ├── local.properties # Android SDK path configuration
├── package.json
└── README.md
- Node.js
- React Native CLI
- Android Studio (for Android development)
- Install dependencies:
npm install
- Configure the Android SDK path:
- Open
android/local.properties
- Replace the username in the following line with your own:
sdk.dir = /users/YOUR_USERNAME/library/android/sdk
- Open
- Ensure required permissions are added in
AndroidManifest.xml
:<uses-permission android:name="android.permission.CAMERA"/> <uses-feature android:name="android.hardware.camera" android:required="true"/>
- Start the Metro bundler:
npx react-native start
- Build and run the app on Android:
npx react-native run-android
The WebView loads the GlamAR SDK and communicates via window.postMessage
. The SDK events are handled in onMessage
.
- On Android, camera permission is requested using
PermissionsAndroid
. - In
MainActivity.java
,onPermissionRequest
grants camera access for WebView.
Initialize the SDK:
GlamAr.init({
apiKey: 'Your_API_Key',
platform: 'react_native',
category: 'skinanalysis',
configuration: {
skinAnalysis: {
appId: 'Your_Skinanalysis_app_ID',
},
},
});
To Listen the SDK Events.
const photoLoadedSubscription = GlamAr.on('photo-loaded', (data: any) => {
console.log('Photo loaded:', data);
});
const loadedSubscription = GlamAr.on('loaded', (data: any) => {
console.log('glamar loaded', data);
});
// 3) Cleanup on unmount
return () => {
// NativeEventEmitter returns an EmitterSubscription with remove()
photoLoadedSubscription?.remove?.();
loadedSubscription?.remove?.();
};
Method | Description |
---|---|
GlamAr.init(config) |
Initializes the SDK |
GlamAr.reset() |
Clears current applied items |
GlamAr.open() / close() |
Opens or closes the live preview mode |
GlamAr.on(event, cb) |
Registers event listeners |
Event | Description |
---|---|
loaded |
SDK initialized |
opened , closed |
Widget opened or closed |
camera-opened |
Camera successfully accessed |
camera-closed |
Camera stopped |
camera-failed |
Error accessing camera |
subscription-invalid |
API key expired or invalid |
skin-analysis |
Skin analysis data received |
error |
Any error from SDK |
Detailed documentation available at https://www.glamar.io/docs/
- Ensure the device has an active internet connection.
- Verify that camera permission is granted in Android settings.
- Ensure
onPermissionRequest
inMainActivity.java
correctly grants camera permissions.
- Use
console.log(event.nativeEvent.data)
insidehandleMessage
to debug messages received from the WebView.
- Your Name (Project Maintainer)
This project is licensed under [Your License].