Usage
This page describes how to use the SDK
Requirements
The minimum supported SDK version is 21
Databeaver android SDK 0.2.0 and above only supports projects that have been migrated to androidx For more information, read Google's migration guide
Steps
Add the code below to the root build.gradle file
allprojects {
repositories {
...
maven {
url "https://softcomlimited0.bintray.com/databeaversdk"
credentials {
username '<username>'
password '<password>'
}
}
}
}
2. Add the dependency to the module level build.gradle file
implementation 'ng.softcom.databeaversdk:databeaversdk:<latest-version>'
3. Enable data-binding in your module(and also in other modules that depends on it)
buildFeatures {
dataBinding = true
}
4. Sync and build your project
5. Create a DataBeaverSDK instance and configure it with DataBeaverSdkSettings then apply the data and other settings you need
val sdk = DataBeaverSDK(this)
.configure(DataBeaverSdkSettings().apply {
//FormData -> json string
setFormData(formData)//(Mandatory)
//Title to be displayed on the appbar/toolbar
setTitle("Form Title")//(Optional)
})
6. Call the render method on the SDK object
sdk.render()
7. This will render the formData JSON string in a new activity and when done it returns the result back to the activity via onActivityResult
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when(requestCode) {
SDKConstants.DATA_BEAVER_REQUEST_CODE -> {
when (resultCode) {
FormRenderingActivity.RESULT_SUCCESS -> {
val resultString = data?.getStringExtra(SDKConstants.FORM_RESULT)
Toast.makeText(this, "$resultString", Toast.LENGTH_LONG).show()
}
FormRenderingActivity.RESULT_CANCELLED -> {
Toast.makeText(this, "RESULT CANCELLED", Toast.LENGTH_LONG).show()
}
else -> {
val reason = data?.getStringExtra(SDKConstants.FORM_MESSAGE)
Toast.makeText(this, reason, Toast.LENGTH_LONG).show()
}
}
}
}
}
8. The result comes in as a string representation of data beaver result object, this string can be converted back into DataBeaverResult object
val dataBeaverResultString = data?.getStringExtra(SDKConstants.FORM_RESULT)
val dataBeaverResult = Gson().fromJson(dataBeaverResultString, DataBeaverResult::class.java)
9. If your form makes use of google maps ensure you add the google maps API key to your AndroidManifest.xml file’s within the <application> tag
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="API-KRY-HERE" />
Last updated
Was this helpful?