# Getting Started

**Referd's** Android SDK enables you to use the show **Referd** user profile in your app, track app user events, integrate referrals and display Referd's in-app push notifications.

## Setting up Referd SDK

Follow the below steps to start installing **Referd's** Android SDK to your app.

Add JitPack repository to your project's *build.gradle* (or *settings.gradle* if you're on newer versions) file.

```gradle
dependencyResolutionManagement {
    ...
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}
```

Add the following dependency to the application's *build.gradle* file to import Referd's SDK into your project.

```gradle
dependencies {
    ...
    implementation 'com.github.gameballers:gb-mobile-android:1.2.10'  
}
```

{% hint style="info" %}
Make sure that you added the INTERNET permission in your application's ***AndroidManifest.xml** file as follows:*

<pre class="language-xml"><code class="lang-xml"><strong>&#x3C;manifest xmlns:android="http://schemas.android.com/apk/res/android"
</strong>xmlns:tools="http://schemas.android.com/tools">
    ...
    &#x3C;uses-permission android:name="android.permission.INTERNET" />
    ...
&#x3C;/manifest>
    
</code></pre>

{% endhint %}

### To install Firebase Google Play Services dependencies

The SDK uses Firebase Dynamic Links to track referrals and Firebase Messaging for sending push notifications, you'll need to add the following dependencies.

```gradle
dependencies {
    ...
    // Make sure to include this dependency even if you won't include Firebase Messaging
    implementation platform('com.google.firebase:firebase-bom:<latest_version>')
    // Firebase Dynamic Links only - must be included
    implementation "com.google.firebase:firebase-dynamic-links"    
    // Firebase Messaging only - optional depending on whether or not you want to use FCM
    implementation 'com.google.firebase:firebase-messaging'  
}
```

{% hint style="info" %}
For the latest Firebase SDK (BOM, Cloud Messaging, Deep Links, and Google Services) versions check their [release notes](https://firebase.google.com/support/release-notes/android).
{% endhint %}

You also need to add *google-services* plugin to your application.

**App's** *build.gradle* file:

```gradle
plugins {
    ...
    id 'com.google.gms.google-services'
}
```

**Project**'s *build.gradle* file:

```gradle
buildscript{
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:<latest_version>'

    }
}
```

{% hint style="info" %}
Don't forget to include your *google-services.json* to your *app* root after registering it to a Firebase project.

Follow [this](https://firebase.google.com/codelabs/fcm-and-fiam#0) tutorial to learn more on how to register your Android application to Firebase.
{% endhint %}

## Initialize Refer SDK

### Create a GameballApp instance

o create a GameballApp instance you need to call the **getInstance** method and pass it a **Context** instance of the current ***Activity*** holding the GameballApp.

{% tabs %}
{% tab title="Java" %}

```java
GameballApp gameballApp = GameballApp.getInstance(getApplicationContext());
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val gameballApp = GameballApp.getInstance(applicationContext)
```

{% endtab %}
{% endtabs %}

#### Initialize GameballApp Instance

To initialize GameballApp instance in your application class, use the **init** method which takes the following parameters:

<table data-header-hidden><thead><tr><th width="231">Parameter</th><th width="90">Type</th><th width="103">Required</th><th>Description</th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td>Type</td><td><strong>Required</strong></td><td><strong>Description</strong></td></tr><tr><td><code>APIKey</code></td><td><strong>string</strong></td><td><strong>Yes</strong></td><td>Client API key</td></tr><tr><td><code>lang</code></td><td><strong>string</strong></td><td><strong>No</strong></td><td><p>Your platform language preference to view <strong>Referd</strong> Widget with.</p><p><strong>Note:</strong> The language provided should be as per configured languages in your account. If not provided the <strong>Referd</strong> profile widget will be shown with your account default language</p><p><strong>Example:</strong> <code>"en"</code>, <code>"fr"</code>.</p></td></tr></tbody></table>

{% tabs %}
{% tab title="Java" %}
{% code fullWidth="true" %}

```java
// Using the instantiated instance of GameballApp
gameballApp.init("{{your API Key}}", "{{lang}}", "{{your Platform name}}", "{{your Shop name}}");

//You can access the init method directly as follows
GameballApp.getInstance(getApplicationContext()).init("{{your API Key}}", "{{lang}}", "{{your Platform name}}", "{{your Shop name}}");
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// Using the instantiated instance of GameballApp
gameballApp.init("{{your API Key}}", "{{lang}}", "{{your Platform name}}", "{{your Shop name}}")

//You can access the init method directly as follows
GameballApp.getInstance(applicationContext).init("{{your API Key}}", "{{lang}}", "{{your Platform name}}", "{{your Shop name}}")
```

{% endtab %}
{% endtabs %}

### Initialize Firebase Push Notifications

To be able to use Firebase Push Notifications feature through Referd you'd need to first initialize firebase device token by calling the following method right after the ***init*** method or before the registration of the user.

{% tabs %}
{% tab title="Java" %}

```java
// Using the instantiated instance of GameballApp
gameballApp.initializeFirebase();
```

{% endtab %}
{% endtabs %}
