Affectiva affdex-sdk works with Android SDK 22 only?

android

#1

I am trying out the github examples referenced in the Affectiva AI docs.

The examples work with the gradle configuration they come with:

build.gradle

apply plugin: 'com.android.application'

android {


    compileSdkVersion 22
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        setProperty("archivesBaseName", "$project.name-$versionName")
        applicationId "com.affectiva.cameradetectordemo"
        versionName "3.2.0-01"
    }
    buildTypes {
        release {
            minifyEnabled true
        }
    }
    buildToolsVersion '27.0.3'
}

dependencies {
    implementation('com.affectiva.android:affdexsdk:3.+')
}

The problem is, the examples work ONLY with compileSdkVersion and targetSdkVersion both set to 22.
When i enter anything higher, 23 to 27, the apps compile but when i want to start the camera from inside the app, the app crashes with the Error Message

java.lang.IllegalStateException: Camera is unavailable.

Questions:

  1. Why are the Affectiva examples only working with SDK version 22?
  2. How can i use the affdex-sdk with a current version of the Android SDK?

Thanks for your help!


#2

Android introduced the runtime permissions feature in API level 23. An app that targets 23+ must implement runtime permissions logic and request camera permission in order to access the camera.

The purpose of the sample you are referencing is to demonstrate use of the Affectiva SDK, so to avoid the need to add a bunch of runtime permission logic which would be irrelevant to that purpose, it targets API level 22.


#3

Thank you, that was helpful!

To avoid the permission hassle i used this google library:

https://github.com/googlesamples/easypermissions