Skip to main content

Getting started

Installing the SDK

On your build.gradle file add the following dependencies:

implementation('io.yesid.sdk.android:touchless:0.2.2-beta@aar'){
transitive = true
}

On your settings.gradle file add the following urls:

maven {
url 'https://gitlab.com/api/v4/projects/29462567/packages/maven'
}
jcenter()
maven {
url 'https://jfrog.yesid.tech/artifactory/libs-release-local'
}

Permissions

On your AndroidManifest.xml file you need to add the following permissions:

<uses-permission android:name="android.permission.CAMERA" />

On your Main Activity ensure permissions are granted for the above permissions.

private fun allRuntimePermissionsGranted(): Boolean {
for (permission in REQUIRED_RUNTIME_PERMISSIONS) {
permission.let {
if (!isPermissionGranted(this, it)) {
return false
}
}
}
return true
}

private fun getRuntimePermissions() {
val permissionsToRequest = ArrayList<String>()
for (permission in REQUIRED_RUNTIME_PERMISSIONS) {
permission.let {
if (!isPermissionGranted(this, it)) {
permissionsToRequest.add(permission)
}
}
}

if (permissionsToRequest.isNotEmpty()) {
ActivityCompat.requestPermissions(
this,
permissionsToRequest.toTypedArray(),
PERMISSION_REQUESTS
)
}
}

private fun isPermissionGranted(context: Context, permission: String): Boolean {
if (ContextCompat.checkSelfPermission(
context,
permission
) == PackageManager.PERMISSION_GRANTED
) {
Log.i(TAG, "Permission granted: $permission")
return true
}
Log.i(TAG, "Permission NOT granted: $permission")
return false
}

companion object {
private const val TAG = "EntryChoiceActivity"
private const val PERMISSION_REQUESTS = 1

private val REQUIRED_RUNTIME_PERMISSIONS =
arrayOf(
Manifest.permission.CAMERA
)
}

Then onCreate you can check if the permission are available or not

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Your other code here
if (!allRuntimePermissionsGranted()) {
getRuntimePermissions()
}
}