> For the complete documentation index, see [llms.txt](https://catchdocs.gitbook.io/catch-customer-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://catchdocs.gitbook.io/catch-customer-documentation/interactivity-catch/add-catch-to-another-app/android-apps.md).

# Android Apps

## Overview

The Catch Lite library is derived from the codebase of the existing Catch application, written in the Flutter framework. Core functionality from the main application is compiled as Native libraries.

The below guide details how the CatchLite Library can be integrated into an existing Android (Native) application.

{% hint style="success" %}
This guide has been written to work with an empty Android Studio project with the following settings:

* "Empty View Activity" template
* Minimum SDK version 26
* Kotlin
* Groovy DSL
  {% endhint %}

## Authentication

1. Create a new account on [MyGet](https://www.myget.org/), where the Catch Library is hosted
2. Share your MyGet username with your account manager at Catch.
3. You will receive a confirmation email from MyGet confirming that you have been added to the CatchLite feeds.

### Setup Repositories

Add the following fragment to the `repositories {}` block in `settings.gradle`, making sure to substitute the correct MyGet username/password.

```kotlin
maven { url "https://jitpack.io" }
maven {Add commentMore actions
    url 'https://www.myget.org/F/catch-lite/maven'
    credentials {
        username "MYGET_USERNAME"
        password "MYGET_PASSWORD"
    }
}
maven {
    credentials {
        username "MYGET_USERNAME"
        password "MYGET_PASSWORD"
    }
    url 'https://www.myget.org/F/urbanminded-pop-android/maven'
}
maven {
    url "https://storage.googleapis.com/download.flutter.io"
}
```

{% hint style="info" %}
**Note:** ensure the MyGet credentials are not committed to source control; for production use it may be preferable to use local properties or environment variables via `System.getenv()`.
{% endhint %}

### Add Catch and Flutter Libraries

Add the following dependencies to `app/build.gradle`:

```
implementation 'com.catchinc:catch-lite:1.0.0'Add commentMore actions
releaseImplementation 'com.catchinc.mobile_lib:flutter_release:1.1.0'
debugImplementation 'com.catchinc.mobile_lib:flutter_debug:1.1.0'
```

After this step, sync the Gradle sections and verify the application can build. Recent versions of Android Studio may prompt to add`libs.androidx.navigation.fragment.ktx` and `libs.androidx.navigation.ui.ktx`; this is fine.

### Add Button to trigger Catch

Update the default view in `app/src/main/res/layout/activity_main.xml` with a button to trigger the Catch:

```kotlin
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/myButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open Catch" />
</LinearLayout>
```

### Make MainActivity implement CatchEventListener

Update `MainActivity.kt` so that the activity class implements `CatchClientListener`:

```kotlin
package ad.catchinc.myapplication

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.catchinc.catch_lite.CatchClientListener

class MainActivity : AppCompatActivity(), CatchClientListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }

    override fun onCatchDismiss() {}
    override fun onCatchPresent() {}
    override fun onError(message: String?) {}
    override fun onScreenNearBy(count: Int) {}
    override fun onScreenPressed(locationName: String?) {}
    override fun onScreenSwipe(locationName: String?, contentId: String?) {}
    override fun onWidgetPressed(contentId: String?, widgetID: String?) {}
}
```

This allows your code to receive [events](https://catchdocs.gitbook.io/catch-customer-documentation/interactivity-catch/add-catch-to-another-app/android-apps.md) from the Catch Lite library.

### Integrate Catch Client with Button

Add the following code to `onCreate()` in `MainActivity`:

```kotlin
val catchClient = CatchClient(this).apply {
    setCallback(this@MainActivity)Add commentMore actions
    init()
}

val openCatchBtn: Button = findViewById(R.id.myButton)
openCatchBtn.setOnClickListener {
    catchClient.present()
}
```

### Build and Run

It should now be possible to run the project on a mobile device and view Catch-enabled content.
