# Usage

#### Requirements <a href="#requirements" id="requirements"></a>

* The minimum supported SDK version is 21
* Databeaver android SDK 0.2.0 and above only supports projects that have been migrated to [androidx](https://developer.android.com/jetpack/androidx/) For more information, read Google's [migration guide](https://developer.android.com/jetpack/androidx/migrate)

#### Steps

1. Add the code below to the ***root build.gradle*** file&#x20;

```groovy
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

```groovy
implementation 'ng.softcom.databeaversdk:databeaversdk:<latest-version>'
```

3\. Enable data-binding in your module(and also in other modules that depends on it)

```groovy
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

```kotlin
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

```kotlin
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

```kotlin
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

```kotlin
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

```markup
<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="API-KRY-HERE" />
```

<br>

<br>

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://softcom-1.gitbook.io/docs/master/android-sdk-1/useage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
