Kotlin

Output source code snippets

In Appfigurate Emulator app, under the KOTLIN/ANDROID LIBRARY INTEGRATION section:

Tap Output implementation then tap Console.

Tap Output AndroidManifest.xml snippet then tap Console.

The output will be displayed in Android Studio, under the Logcat tab. Filter the output to application nz.co.electricbolt.appfigurate

Create nz.co.electricbolt.appfiguratelibrary.Configuration subclass

In your app, add a Kotlin class called Configuration.kt

Paste the Kotlin implementation file output to the Console in Output source code snippets.

Note: your public key output to the Console in Output source code snippets will be different to the public key in the following example.

package com.yourcompany.yourapp

import nz.co.electricbolt.appfiguratelibrary.annotations.*

public class Configuration extends nz.co.electricbolt.appfiguratelibrary.Configuration {

    @BooleanProperty(description = "Log debug output to console", restart = false)
    var debugLogging = false

    @StringPropertyListEdit(regularExpression = "https://[\\w\\.-]+\\.yourappserver.com/.*",
        description = "Application server url", restart = false, keys = {"Dev", "Prod"},
        values = {"https://dev.yourappserver.com/api", "https://www.yourappserver.com/api"})
    var String? serverURL = null

    override fun allowInvalidSignatures(): Boolean {
        return BuildConfig.DEBUG
    }

    override fun publicKey(): String {
        // 41 36 87 71 0D 05
        return """-----BEGIN PUBLIC KEY-----\n
            MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4TZnKfGeXttN7Rr3eiAZ\n
            PMEPsZvbo7lgIpMh6OjgBsoqkJJP0yXXLtpqsBCv8vm7RYqCn5+yfkiCQiXvkJBz\n
            FSKmLF9EPR9l1H+32Id82dDuseD70D66puPUHjciEgmU18DpW2NVvTAykMwTEsiR\n
            0h/ExBEhUe75qtwlVno8cMFbEfVtiGbKECvWIr122ED71T0Jt2Bcxqx1a7c1hPIV\n
            RwLxIfWfE0+2rB9nJVPBgsTVPywibDvjio82FousyMDmvkAbMq5iyuyvJ0+5bATz\n
            o12GEt5lSiQlCMzfmkWYBROMDCh27qGFVVo1XAUCVsMfsW9n4iQcoLAdUp/LI3B3\n
            ywIDAQAB\n
            -----END PUBLIC KEY-----\n
            """.trimIndent()
    }

    override fun reset() {
        debugLogging = true
        serverURL = "https://www.yourappserver.com/api"
    }

}

Edit Android.xml manifest

Paste the meta-data and provider into your app's AndroidMainfest.xml that were output to the console in Output source code snippets.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools" package="com.yourcompany.yourapp">

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="APLConfigurationSubclass"
            android:value=".Configuration"/>
        <provider
            android:authorities="quickstart"
            android:name="nz.co.electricbolt.appfiguratelibrary.CommandContentProvider"
            android:exported="true">
        </provider>
...        

Test your configuration

To test that you've successfully updated your app to use Appfigurate:

Compile and run Quickstart to the same Emulator instance that Appfigurate Emulator was run from previously.

Tap the Appfigurate app icon.

Tap the Quickstart row. Appfigurate will read the configuration from the Quickstart app.

Appfigurate will now display the following screen:

Since we added a @BooleanProperty for debugLogging and @StringPropertyListEdit for serverURL, you can now change these configuration items at runtime. Tap Apply⌄ to apply the configuration to the Quickstart app.

Now jump to Supported property types.

Last updated