Usage
Setup
val camera = FaceAuthenticationCamera
val configuration =
FaceAuthConfigurationBuilder.setUserLicense(stringResource(id = "LicenseKey"))
//Inside a composable function just do the following
@Composable
fun MyComposable() {
camera.FaceAuthCamera(
configurationBuilder = configuration,
firstImage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888),
secondImage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888),
onMatchResultsFirstImage = { FaceMatchResults ->
},
onMatchResultsSecondImage = { FaceMatchResults ->
},
)
}
Using Fragments in Kotlin or Java
In your activity_main.xml
file add the following:
<androidx.fragment.app.FragmentContainerView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/main_container" />
//Create a FaceDetectionFragment and call the Face Camera
class FaceDetectionFragment : Fragment() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = ComposeView(requireContext())
view.apply {
setContent {
Column(
modifier = Modifier.fillMaxSize(),
) {
MyComposable()
}
}
}
return view
}
@Composable
fun MyComposable() {
val camera = FaceAuthenticationCamera
val configuration =
FaceAuthConfigurationBuilder.setUserLicense(stringResource(id = "LicenseKey"))
camera.FaceAuthCamera(
configurationBuilder = configuration,
firstImage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888),
secondImage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888),
onMatchResultsFirstImage = { FaceMatchResults ->
},
onMatchResultsSecondImage = { FaceMatchResults ->
},
)
}
}
On your activity then call the FaceDetectionFragment
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportFragmentManager.beginTransaction()
.replace(R.id.main_container, FaceDetectionFragment()).commit()
}
}