# Init Android SDK

### Import Android Gotadi SDK vào project <a href="#import-android-gotadi-sdk-vao-project" id="import-android-gotadi-sdk-vao-project"></a>

#### 1. Download `AndroidGotadiSDK` từ SDK link. <a href="#id-1-download-androidgotadisdk-tu-sdk-link" id="id-1-download-androidgotadisdk-tu-sdk-link"></a>

#### 2. Import Module `AndroidGotadiSDK` vào project Android <a href="#id-2-import-module-androidgotadisdk-vao-project-android" id="id-2-import-module-androidgotadisdk-vao-project-android"></a>

<div><figure><img src="/files/qVtduIfqq2pmc7tEL7hm" alt=""><figcaption></figcaption></figure> <figure><img src="/files/VQp2ju2i90FhsRt6PydO" alt=""><figcaption></figcaption></figure> <figure><img src="/files/YOfXnzHmZ72sAIMsfODJ" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}

```javascript
Sau khi import sẽ thấy config `include ':AndroidGotadiSDK'` trong file `settings.gradle`
```

{% endhint %}

```gradle
rootProject.name = "My Application"
include ':app'
include ':AndroidGotadiSDK'
```

#### 3. Add dependencies `AndroidGotadiSDK` trong file `build.gradle` để sử dụng thư viện <a href="#id-3-add-dependencies-androidgotadisdk-trong-file-buildgradle-e-su-dung-thu-vien" id="id-3-add-dependencies-androidgotadisdk-trong-file-buildgradle-e-su-dung-thu-vien"></a>

```gradle
dependencies {
    implementation project(path: ':AndroidGotadiSDK')
}
```

#### 4. Add maven repositories `AndroidGotadiSDK` trong file `build.gradle` để sử dụng libs của SDK <a href="#id-4-add-maven-repositories-androidgotadisdk-trong-file-buildgradle-e-su-dung-libs-cua-sdk" id="id-4-add-maven-repositories-androidgotadisdk-trong-file-buildgradle-e-su-dung-libs-cua-sdk"></a>

```gradle
allprojects {
    repositories {
        maven {
            url "${project.rootDir}/AndroidGotadiSDK/libs"
        }
        maven {
            url 'https://storage.googleapis.com/download.flutter.io'
        }
    }
}
```

### Example Code khởi tạo AndroidGotadiSDK <a href="#example-code-khoi-tao-androidgotadisdk" id="example-code-khoi-tao-androidgotadisdk"></a>

* Import package của SDK để sử dụng các function khởi tạo activity Gotadi Search Book

```kotlin
import com.gotadi.AndroidGotadiSDK.GotadiAdapter
import com.gotadi.AndroidGotadiSDK.GotadiCallback
import com.gotadi.AndroidGotadiSDK.GotadiPartnerSetting
```

* Khởi tạo GotadiSDK để tối ưu performance
* Init environment Setting trước khi run GotadiActivity
* Init setting `environment` of partner with `params`:
  * `env` : Môi trường deploy `[uat | prod]`
  * `partnername`: Partner Name , example: `“vib”`
  * `language`: Ngôn ngữ hiển thị `[”vi” | “en”]`
  * `token`: `JWT Token` lấy được sau khi authorize từ API authentication của Gotadi
  * `theme` : `primary`, `secondary`

```kotlin
import com.gotadi.AndroidGotadiSDK.AndroidGotadiSDK
import com.gotadi.AndroidGotadiSDK.GotadiCallback
import com.gotadi.AndroidGotadiSDK.GotadiPartnerSetting

class GTDExampleAppActivity : AppCompatActivity() {
    private var gotadiSDK: AndroidGotadiSDK? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_app)
        val button = findViewById<Button>(R.id.myappButton)
        //Call API and get gotadi Token
        gotadiSDK = AndroidGotadiSDK(
            this,
            setting = GotadiPartnerSetting("uat", "vib", "vi","token","
primary"))
        button.setOnClickListener {
            val intent = gotadiSDK?.createGotadiIntent()
            intent?.let {
                startActivity(intent)
            }
            gotadiSDK?.actionHandler?.bookkingResultCallback = object : GotadiCallback {
                override fun onCallPayment(gotadiActivity: Context, bookingNumber: String) {
                                        //Handle payment after checkout here
                    println("bookkingResultCallback - onCallPayment")
                    gotadiActivity.startActivity(Intent(gotadiActivity, GTDPartnerPaymentActivity::class.java))
                    println(bookingNumber)
                }
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
                //Destroy SDK avoid leak memory
        gotadiSDK?.dispose()
        println("GTDExampleAppActivity is destroy")
    }
}
```


---

# 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://developer.gotadi.com/vietnamese/doi-tac-b2b2c/phuong-thuc-sdk/initiate-sdk/init-android-sdk.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.
