...
You need Android Studio 3.3.x, or later. You may either start with a new project or an existing project.
...
Start with an
...
Existing Project
Goto Tools|Kotlin|Configure Kotin in Project.
- You will present with a dialog with two options. Choose "Android with Gradle":
- Choose the "app" to enable Kotlin integration (choose the latest version corresponding to the plugin on your IDE):
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
apply plugin: 'com.android.application' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' // omitted... dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } |
Start with a New Project
- Start with the new project wizard on Android studio.
- Choose "Kotlin" language:
...
- Follow the initial setup as described the Android Integration documentation, take especially care of:
- Dependencies
- The handling of native libraries.
- Upgrading pro-guard.
Implement the GreenIDListener interface on your activity, for example:
Code Block language java theme Confluence title GreenIDActivity.kt class GreenIDActivity : AppCompatActity(), GreenIDListener { override fun onGreenIDSuccess(resultCode: Int, verificatationToken: String?, verificationStatus: String?) { // Your business logic here } override fun onGreenIDFailed(resultCode: Int, message: String?, description: String?) { // Handle all failures when (result) { ResultCode.NO_NETWORK -> noNetwork() ResultCode.BACK -> userPressedBack() else -> handleGeneralGreenIDError(resultCode,message) } } }
Note - Override is a required keyword in Kotlin.
- When overriding a function, you do not have specify the access scope:
- Public stays public,
- Protected stays protected!
Write a function to start the GreenID™ SDK:
Code Block language java title GreenActivity.kt // In GreenActivity.kt private fun startGreenID() { val configBundle = Bundle().apply { putString("accountId", "account-id-as-provided") putString("baseUrl", "https://simpleui-test-uat1au.vixverify.com/") // Change this putString("apiCode", "api-code-as-provided") putString("countryCode", "XX") putString("mode", "onboarding") } try { GreenID.getInstance(applicationContext).start(configBundle, this) catch(e: GreenIDConfigException) { // You have to handle this! } }
Start the GreenID™, for example on a button/view click:
Code Block // onCreate: startGreenIdBtn.setOnClickListener { startGreenID() }
...