Skip to content

pixelbin-io/glamar-android

Repository files navigation

GlamAR Android SDK

Maven Central License

Overview

GlamAR is a powerful Augmented Reality SDK for Android that enables virtual try-on experiences for makeup, jewelry, and other beauty products. The SDK provides an easy-to-integrate solution with real-time AR capabilities, face detection, and product visualization features.

Features

  • Real-time virtual makeup try-on
  • Multiple product category support
  • Camera and image-based preview modes
  • Real-time face tracking and analysis
  • Easy integration with Android applications
  • Snapshot functionality
  • High-performance WebView-based rendering
  • Original/Modified view comparison
  • Configurable parameters

Installation

Maven Central

The GlamAR SDK is available on Maven Central. Add the following dependency to your app's build.gradle:

dependencies {
    implementation 'io.pixelbin.glamar:glamar:2.0.6'
}

Manual Installation

Alternatively, you can manually include the .aar file:

  1. Place the .aar file in your project's libs directory
  2. Add the following to your app's build.gradle:
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'com.squareup.okhttp3:okhttp:4.11.0'
}

Sync your project with Gradle files.

Required Permissions

Add these permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" /> <!-- Required for camera preview mode -->

Initialization

Initialize the SDK in your Application class to ensure it is set up when your app starts.

class MyApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY")
    }
}

Don't forget to register your Application class in the AndroidManifest.xml:

<application
    android:name=".MyApplication"
    ... >
    <!-- Other configurations -->
</application>

This "init" will prompt our SDK to create a webview and open our SDK in it.

AR View

Setup

To use the webview we have created you will need to add it your layout. Paste the following code inside your layout xml file where you want to show the webview.

<FrameLayout
    android:id="@+id/glamARView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

Inside the activity class add the following code:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // This passes the activity context to the webview
        GlamArWebViewManager.setUpActivityContext(this)

        // This adds the webview created by SDK in the layout
        GlamArWebViewManager.getPreparedWebView()?.let { webView ->
            val glamARView = findViewById<FrameLayout>(R.id.glamARView)
            glamARView.apply {
                addView(webView)
            }
        }
    }
}

You should be able to see GlamAR SDK page being loaded.

Initialization options

Opens the SDK Home screen with relevant category module setup.

import io.pixelbin.glamar.model.GlamAROverrides

val overrides = GlamAROverrides(
    category = "sunglasses",
)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY", overrides)

Open the SDK with Live mode (web camera) straightaway. This bypasses the SDK home screen.

import io.pixelbin.glamar.model.GlamAROverrides
import io.pixelbin.glamar.model.Configuration
import io.pixelbin.glamar.model.GlobalConfig

val overrides = GlamAROverrides(
    category = "sunglasses",
    configuration = Configuration(
        global = GlobalConfig(
            openLiveOnInit = true,
        ),
    )
)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY", overrides)

Open SDK with disabled previous button and cross button.

import io.pixelbin.glamar.model.GlamAROverrides
import io.pixelbin.glamar.model.Configuration
import io.pixelbin.glamar.model.GlobalConfig

val overrides = GlamAROverrides(
    category = "sunglasses",
    configuration = Configuration(
        global = GlobalConfig(
            disableClose = true,
            disableBack = false
        ),
    )
)
GlamAr.init(context = this, accessKey = "YOUR_ACCESS_KEY", overrides)

Applying SKUs

Apply a SKU:

GlamAr.applySku(skuId = "SKU_ID")

Taking Snapshot

Take a snapshot of the current view:

GlamAr.snapshot()

Permissions

Ensure that you handle permissions appropriately, especially for camera access when using openLiveOnInit.

override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<out String>,
    grantResults: IntArray
) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    GlamArPermissionHandler.onRequestPermissionsResult(requestCode, grantResults)
}

Event Handling

Event listeners are essential soon after initialization is called to start listening to GlamAR SDK callback events.

addEventListener

// Can be any event type sent from SDK
GlamAR.addEventListener("sku-applied"){
    GlamArLogger.d("TAG", "sku-applied callback")
}

removeEventListener

Can also unregister from listening to events previously registered to but calling

GlamAR.removeEventListener("sku-applied")

Best Practices

  1. Always handle permissions appropriately:
override fun onRequestPermissionsResult(
  requestCode: Int,
  permissions: Array<out String>,
  grantResults: IntArray
) {
  super.onRequestPermissionsResult(requestCode, permissions, grantResults)
  GlamArPermissionHandler.onRequestPermissionsResult(requestCode, grantResults)
}
  1. Initialize the SDK early in your application lifecycle
  2. Handle callbacks for better user experience
  3. Use appropriate preview modes based on your use case
  4. Implement proper error handling

Version History

  • 1.0.2 (Latest)
    • New updated GlamAR structure
  • 1.0.1
    • Maven Central release
    • Enhanced face tracking
    • Improved performance
    • Bug fixes and stability improvements

Support

For support and bug reports, please create an issue in our GitHub repository or contact our support team at support@pixelbin.io.

License

GlamAR SDK is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages