# Getting Started

### Getting Started

To start using the ReferralHero SDK, you will need to add it to your project as a dependency.

#### Step 1. Add the JitPack repository to your build.gradle  file

Add it in your root `build.gradle/setting.gradle`  at the end of repositories:

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

#### Step 2. Add the following to your `build.gradle` file:

```xml
dependencies {
        implementation 'com.github.maitre-app:ReferralHero-Android:$latest.release'
}
```

#### for KTS *(1.0.6 as in Last Version available)*:

```
dependencies {
             implementation("com.github.maitre-app:ReferralHero-Android:1.0.6")
}
```

#### Step 3. Add Permission:

The ReferralHero SDK requires the following permissions. Add them to your AndroidManifest.xml file if they are not already present:

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

If you are not targeting the Google Play Store, you need to add the following permission:

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

**Step 4. Set up Proguard:**

```xml
-keep class com.sdk.referral.** { *; }
-keep public class com.android.installreferrer.** { *; }
```

If you are not publishing your app in the Google Play Store, add the following `com.sdk.rh` rule:

```xml
-keep public class com.sdk.referral.** { *; }
```

#### Step 5. Set up install referrer intent:

If you are working with a store that supports the `INSTALL_REFERRER` intent, you can capture this with a broadcast receiver. Add the following `receiver` inside the `application` tag in your `AndroidManifest.xml`:

```xml
<receiver
            android:name="com.sdk.referral.receiver.RhReferrerReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
</receiver>

```

This receiver will retrieve the install referrer using below code in your file where you want to retrieve install referrer and register `BroadcastReceiver` in your main activity.

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

```java
public class MainActivity extends AppCompatActivity{
    private final BroadcastReceiver mUpdateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //put your logic here
       }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
    }
    @Override
    protected void onPause() {
     LocalBroadcastManager.getInstance(this).unregisterReceiver(mUpdateReceiver);
        super.onPause();
    }

    @Override
    protected void onResume() {
      LocalBroadcastManager.getInstance(this).registerReceiver(mUpdateReceiver, new IntentFilter(new RhReferrerReceiver().getACTION_UPDATE_DATA()));
        super.onResume();
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
class MainActivity : AppCompatActivity() {
   private val mUpdateReceiver: BroadcastReceiver = object : BroadcastReceiver() {
       override fun onReceive(context: Context, intent: Intent) {
           //put your logic here
       }
   }

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)
   }

   override fun onPause() {
       LocalBroadcastManager.getInstance(this).unregisterReceiver(mUpdateReceiver)
       super.onPause()
   }

   override fun onResume() {
       LocalBroadcastManager.getInstance(this).registerReceiver(
           mUpdateReceiver, IntentFilter(
               RhReferrerReceiver().ACTION_UPDATE_DATA
           )
       )
       super.onResume()
   }
}
```

{% endtab %}
{% endtabs %}

If you are using a different broadcast receiver, you will need to set it up to communicate with the ReferralHero SDK. Follow these instructions to enable communication with the ReferralHero SDK broadcast receiver.

**Multiple broadcast receivers**

The ReferralHero SDK supports the `INSTALL_REFERRER` intent using a broadcast receiver. If several sources need to register a receiver, you will need to add your own `BroadcastReceiver`.

This receiver will call all the other receivers you want to support. Here is an example of a broadcast receiver:

```java
<receiver
    android:name="com.your.app.InstallReceiver"
    android:permission="android.permission.INSTALL_PACKAGES"
    android:exported="true" >
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>
```

If you are using your own broadcast receiver, you can pass the intent content to other receivers. Make sure to pass this information to the Adjust broadcast receiver and any others that need it:

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

```java
public class InstallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Rh receiver.
        new RhReferrerReceiver().onReceive(context, intent);
      
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
class InstallReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        // Rh receiver.
        context?.let { RhReferrerReceiver().onReceive(it, intent) }
    }
}    
```

{% endtab %}
{% endtabs %}

#### Step 6. Integrate the SDK into your App:

If you are integrating the Adjust SDK into a standard app, follow the Setup SDK steps below.

### **Setup SDK**

We recommend using a global Android [Application](http://developer.android.com/reference/android/app/Application.html) class to initialize the ReferralHero SDK. If you do not have this set up, follow these steps:

1. Create a class that extends the `Application`.
2. Open the `AndroidManifest.xml` file and locate the `<application>` element.
3. Add the `android:name` attribute and set it to the name of your application class. For example, if your `Application` class is named `GlobalApplication`:

```xml
<application
   android:name=".GlobalApplication"
   <!-- ... -->
 </application>
```

4. In your Application class, find or add the `onCreate` method. Add the following code to initialize the ReferralHero SDK:

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

```java
public class GlobalApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        RH.initRHSDK(this,"api_token", "Campaign_uuid");
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
class GlobalApplication : Application() {
  
   override fun onCreate() {
       super.onCreate()
        val rh = RH.initRHSDK(this,"api_token", "Campaign_uuid")
        // or
        val rh = RH.initRHSDK(this, null, null) // if you defined the token on meta-data in AndroidManifest.xml
   }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can find your **ReferralHero API token** and **Tracking Code** in your ReferralHero dashboard.
{% endhint %}

Get your API\_TOKEN from the ReferralHero Dashboard -> API : <https://app.referralhero.com/dashboard/apis>&#x20;

<figure><img src="/files/LWisakiEgBMtKyvpVS7q" alt=""><figcaption></figcaption></figure>

Back in the ReferralHero dashboard, click to edit your desired Campaign

<figure><img src="/files/t0Xk41jVWZkQ1jEMOb9Z" alt=""><figcaption></figcaption></figure>

Then the Installation tab, then Mobile App Installation

<figure><img src="/files/Nn18HlQ1HHmo4DgxJGnk" alt=""><figcaption></figcaption></figure>

Get your UUID: The 12-letter id that starts with ‘MF’ in *Edit Campaign > launch > Mobile app installation*, e.g. MFxxxxxxxxxx

<figure><img src="/files/gIShBRDsUkvAPaB1fCso" alt=""><figcaption></figcaption></figure>

Now, the initRHSDK should look like this:

```kotlin
val rh = RH.initRHSDK(this,"MFxxxxxxxxxx", "0e5eexxxxxxxxxxxxxxxxxxxxxcead")
or
val rh = RH.initRHSDK(this, null, null)
```

This step is mandatory to Set up your ReferralHero API token and Tracking Code in your AndroidManifest.xml file. Without this ReferralHero SDK does not work properly or you can not use SDK Features.

You should add it to your app's AndroidManifest.xml. More about this can be found on ReferralHero dashboard > *Campaign* > *Installation* > *Instructions.*

*Following the values we got for our campaign:*

```xml
<meta-data
            android:name="com.sdk.referral.RhKey"
            android:value="0e5eexxxxxxxxxxxxxxxxxxxxxxx" />
```

```html
 
 <meta-data
            android:name="com.sdk.referral.uuid"
            android:value="MFxxxxxxxxx" />
```

5. In the Goal section of your Campaign settings, ensure you have added the Google Play and Apple App Store links and a default referral link for desktop web users.

<figure><img src="/files/dEfT56vhkDFqD064dVWs" alt=""><figcaption></figcaption></figure>

Well done! You should now be able to build and run your campaign. Before using the more advanced features of the SDK, you should make sure you have reviewed the following important concepts:

* Getting Started
* Setup SDK
* [Checkout Github Sample](https://github.com/maitre-app/ReferralHero-Android)

There are a few major components in the SDK that you can include in your app check out [Public Methods](/integrate/mobile-sdks/android-sdk/public-methods.md).

## Tracking Referrals

Now that you have implemented the SDK, you can start identifying and tracking referrals!

For that, you will need 2 things:

1. Universal Link
2. Your Integrated App

The RH SDK Pulls information from your Device, like this:

```kotlin
var rh: RH? = RH.instance
val referralParams = ReferralParams()
referralParams.email = signup_email?.editText?.text.toString() //Capture this from user
referralParams.domain = "https://a.domain.co/" //Optional value, and set as default by admin
referralParams.name = Username?.editText?.text.toString() //Capture this from user
referralParams.referrer = referralcode?.editText?.text.toString().trim { it <= ' ' } //Optional value, only necessary if you want to capture the referrer code from user 
referralParams.uuid = "MFxxxxxxxxx"//Get this from RH Dashboard
referralParams.device = rh?.deviceInfo?.getDeviceType()
referralParams.ip_address = rh?.deviceInfo?.getIpAddress()
referralParams.os_type = rh?.deviceInfo?.getOperatingSystem()
referralParams.screen_size = transformResolution(rh?.deviceInfo?.getDeviceScreenSize())
referralParams.status = "custom_event_pending"
```

The format for android screen sizes is not native to RH, and the format should be parsed to RH accepted, such as:<br>

```kotlin
fun transformResolution(input: String?): String {
    val dimensions = input?.split('*')?.map { it.trim().toFloat()}
    return "${dimensions?.get(0)} x ${dimensions?.get(1)}"
}
```

With this information, you should be able to add the subscriber data, with the Get Referrer, Add Subscriber, Create Pending Referral, or Track Referral methods to automatically identify or track a referral:

```kotlin
fun formSubmit()
{
    RH.formSubmit(referralParams)
}
```

To further understand the implementation of these methods, please check the Public Methods section, and our Github Sample Project.


---

# 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://support.referralhero.com/integrate/mobile-sdks/android-sdk/getting-started.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.
