# Android - Kotlin

## Add Internet Permission

In AndroidManifest.xml:

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

## Create a class `EvntalyClient`&#x20;

```kotlin
import okhttp3.*
import org.json.JSONObject
import java.io.IOException

class EvntalyClient(private val projectToken: String, private val developerSecret: String) {
    private val baseUrl = "https://app.evntaly.com/prod"
    private val client = OkHttpClient()
}
```

## Track Event

```kotlin
fun sendEvent() {
    val url = "$baseUrl/api/v1/register/event"
    val payload = JSONObject().apply {
        put("title", "Account License Upgraded")
        put("description", "User upgraded their license to Pro")
        put("message", "take care.")
        put("data", JSONObject().apply {
            put("user_id", "67890")
            put("timestamp", "2025-01-08T09:30:00Z")
            put("referrer", "social_media")
            put("email_verified", false)
        })
        put("tags", JSONArray())
        put("notify", true)
        put("icon", "⤴️")
        put("apply_rule_only", false)
        put("user", JSONObject().apply {
            put("id", "0f6934fd-99c0-41ca-84f4")
        })
        put("type", "Page View")
        put("sessionID", "20750ebc-dabf-4fd4-9498-443bf30d6095_bsd")
        put("feature", "Backend API")
        put("topic", "@api")
    }
    
    val body = RequestBody.create("application/json".toMediaTypeOrNull(), payload.toString())
    val request = Request.Builder()
        .url(url)
        .post(body)
        .addHeader("Content-Type", "application/json")
        .addHeader("pat", projectToken)
        .addHeader("secret", developerSecret)
        .build()
        
    client.newCall(request).enqueue(object : Callback {
        override fun onFailure(call: Call, e: IOException) {
            println("Event send failed: ${e.message}")
        }
        
        override fun onResponse(call: Call, response: Response) {
            println("Event sent: ${response.isSuccessful}")
        }
    })
}
```

## Identify User&#x20;

```kotlin
fun identifyUser() {
    val url = "$baseUrl/api/v1/register/user"
    val payload = JSONObject().apply {
        put("id", "0f6934fd-99c0-41ca-3333")
        put("email", "Alameer@evntaly.com")
        put("full_name", "Alameer Ashraf")
        put("organization", "Evntaly")
        put("data", JSONObject().apply {
            put("id", "Alameer")
            put("email", "Alameer@Decaud.com")
            put("Location", "Egypt")
            put("timezone", "Africa/Cairo")
        })
    }

    val body = RequestBody.create("application/json".toMediaTypeOrNull(), payload.toString())
    val request = Request.Builder()
        .url(url)
        .post(body)
        .addHeader("Content-Type", "application/json")
        .addHeader("pat", projectToken)
        .addHeader("secret", developerSecret)
        .build()
        
    client.newCall(request).enqueue(object : Callback {
        override fun onFailure(call: Call, e: IOException) {
            println("User identify failed: ${e.message}")
        }

        override fun onResponse(call: Call, response: Response) {
            println("User identified: ${response.isSuccessful}")
        }
    })
}
```

For additional help, contact support at **<support@evntaly.com>**.


---

# 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://evntaly.gitbook.io/evntaly/sdks/curl/android-kotlin.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.
