# Android

{% hint style="info" %}
Latest Version: [1.2.1](https://github.com/surveysparrow/surveysparrow-android-sdk/releases/tag/1.2.1)
{% endhint %}

Below are the various processes involved in setting up SpotChecks on Android. Kindly refer example applications [here](https://github.com/surveysparrow/surveysparrow-android-sdk/tree/master/ExampleApp)

### Installation

Insert the following in your **build.gradle** file at the end of the repositories section.

```gradle
allprojects {
  repositories {
    ...
    ...
    maven { url 'https://jitpack.io' }
  }
}
```

Add the following line to your app modules, present in the **build.gradle** file within the **dependencies** section.

```gradle
implementation 'com.github.surveysparrow:surveysparrow-android-sdk:1.2.0'
```

The SurveySparrowSdk requires Internet access to fetch surveys and submit answers. So, add the following permissions to the **AndroidManifest.xml** file.

```groovy
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```

Below are the necessary imports before initializing the Spotchecks.

```kotlin
import com.surveysparrow.surveysparrow_android_sdk.SpotCheck
import com.surveysparrow.surveysparrow_android_sdk.trackEvent
import com.surveysparrow.surveysparrow_android_sdk.SpotCheckConfig
import com.surveysparrow.surveysparrow_android_sdk.trackScreen
```

***

Also for **voice transcription** support, add the following permissions to the app.

```xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
```

### Initialization

1. SpotCheckConfig needs to be declared in the composable function

**Anonymous users**

If you wish not to keep track of users' data, you can follow the below syntax for initialization.

```kotlin
val context = LocalContext.current 
val spotCheckConfig = remember {
 SpotCheckConfig(
   domainName = "<your_domain>",
   targetToken = "<target_token>", 
   userDetails = hashMapOf(),
   variables = mapOf(),
   customProperties = mapOf(), 
   preferences = context.getSharedPreferences("spotcheck", Context.MODE_PRIVATE)// Mandatory for Anonumous Users, 
   sparrowLang: "ta" // Eg: ta, te, ml, hi, en 
 )
}
```

**Known Users**

If you wish to keep track of users' data and perform conditional Survey triggers, you can follow the below syntax for initialization.

<pre class="language-kotlin"><code class="lang-kotlin"><strong>val spotCheckConfig = remember {
</strong> SpotCheckConfig(
   domainName = "&#x3C;your_domain>",
   targetToken = "&#x3C;target_token>", 
   variables = mapOf(
       "&#x3C;api_identifier_of_variable>" to "&#x3C;variable_value>"
   ),
   customProperties = mapOf(
       "&#x3C;custom_property_name>" to "&#x3C;custom_property_value>"
   ), 
   userDetails = hashMapOf(
       "email" to "example@email.com",
       "firstName" to "&#x3C;your-first-name>",
       "lastName" to "&#x3C;your-last-name>",
       "mobile" to "&#x3C;user_mobile>",
       "uuid" to "&#x3C;uuid_value>" // Optional
   ), 
   sparrowLang: "ta" // Eg: ta, en,  
  )
}
</code></pre>

2. Then, add the SpotCheck Composabe Function to all the screens where you want to display the surveys.

```kotlin
@Composable
fun SpotCheckScreen(spotCheckConfig: SpotCheckConfig) {
    Scaffold() {}
    SpotCheck(spotCheckConfig)
}
```

**Note:** Add the spotCheckConfig variable outside of the scaffold.

### Screen Track

It provides the ability to keep track of screens the users are visiting and to enable the survey trigger on that screen.

#### Syntax:

```swift
LaunchedEffect(Unit) {
    trackScreen(screen= "ScreenName", config = spotCheckConfig)
}
```

#### Example:

If a survey needs to be triggered on the payment page, the name of the ScreenName should be specified in the TrackScreen function.

<pre class="language-kotlin"><code class="lang-kotlin"><strong>LaunchedEffect(Unit) {
</strong>    trackScreen(screen= "paymentScreen", config = spotCheckConfig)
}
</code></pre>

### Event Track

It provides the ability to keep track of events which when triggered, will enable the survey to be popped.&#x20;

#### Syntax:

```swift
spotCheck.trackEvent("ScreenName", {"EventName": {}});
```

#### Example:

If a survey needs to be triggered when the user completes a payment, then the TrackEvent function should be called with the respective ScreenName and optional custom properties.

```swift
spotCheck.trackEvent("paymentScreen", {"paymentComplete": {
    "email":"naveen@surveysparrow.com",
    "paymentStatus":true
}});
```

{% hint style="info" %}
Make sure to have the eventName configured in the Checks section of the configure panel
{% endhint %}


---

# 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://surveysparrow.gitbook.io/spotchecks/how-to-use-spotchecks/mobile-spotchecks/android.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.
