Gradle Settings

  1. Add the MDK distribution repository URL to gradle.properties.
maven.messay=https://developer.messay.ndk-group.co.jp/maven/
  1. Add the authentication credentials for the MDK distribution site to local.properties.

The username is the same as the one used to log in to the MDK dashboard. For the password, use the authentication token generated from the Settings menu.

maven.messay.username=<Username>
maven.messay.password=<Token>
  1. Add the MDK distribution repository to the project’s build.gradle.kts.
import java.util.Properties

val localProperties = Properties().apply {
    val f = file("local.properties")
    if (f.exists()) {
        load(f.inputStream())
    }
}
dependencyResolutionManagement {
    repositories {
        google {
            mavenContent {
                includeGroupAndSubgroups("androidx")
                includeGroupAndSubgroups("com.android")
                includeGroupAndSubgroups("com.google")
            }
        }
        mavenCentral()
        maven(extra["maven.messay"]) { // Add Maven Repository
            credentials {
                username = localProperties.getProperty("maven.messay.username")
                password = localProperties.getProperty("maven.messay.password")
            }
        }
    }
}
  1. Add mdk-compose to the dependencies of the app module.
dependencies {
	implementation("jp.co.ndk_group.lib:mdk-compose:LATEST_VERSION")
}

Create MdkOptions

val options = MdkOptions.Builder()
    .setEnabledMdkTargets(
        setOf(
            MdkTarget.EyeCloseHold(Side.Unspecified),
        )
    )
    .setActionParams(
        eyeCloseHold,
        MdkOptions.HorizontalPairedHoldActionParams(
            thresholdRatio = { side ->
                when (side) {
                    MdkSide.Left -> 0.6f
                    MdkSide.Right -> 0.6f
                }
            },
            requiredMillis = { count -> if (count == 1) 1_000 else 1_500 },
        ),
    )
    .setListner {
		  // You can get current state of MdkTargets like this
		  val eyeCloseHoldState = MdkTarget.EyeCloseHold(Side.Unspecified).currentState()
		  
			when (eyeCloseHoldState) {
	      MdkResult.ScalarActionState.Start -> {
	        // When you close your eyes
	      }
	
	      is MdkResult.ScalarActionState.CountUp -> {
	        // When count up
	        // e.g. playSound()
	      }
	      
	      is MdkResult.ScalarActionState.InProgress -> {
	        // While you close your eyes
	      }      
	      
	      is MdkResult.ScalarActionState.End -> {
	        // When you open your eyes
	        // e.g. someAction(hold.count)
	      }
	      
	      MdkResult.ScalarActionState.None -> {}
	    }
		}
    .build()

Generate MdkClient

val mdkClient = MdkClient.getClient(context, options) // for Android

val mdkClient = MdkClient.getClient(options) // for iOS

ImageAnalysis.Analyzer

Refer:https://developer.android.com/media/camera/camerax/analyze

val analyzer = ImageAnalysis.Builder()
    .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
    .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888)
    .build().apply {
        setAnalyzer(cameraExecutor) {
	           mdkClient.detectAsync( // ImageProxy is closed internally
		           imageProxy = it, 
		           isFrontCamera = true,
	           )
        }
    }