> ## Documentation Index
> Fetch the complete documentation index at: https://docs.adrop.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Android SDK example code and sample projects.

## Overview

Check out the example code and sample projects for the Adrop Android SDK.

***

## Sample Project

You can find the complete sample project on GitHub.

<Card title="Android Sample Project" icon="github" href="https://github.com/OpenRhapsody/adrop-ads-example-android">
  Sample Android app written in Kotlin
</Card>

***

## Quick Start Examples

### Banner Ad (Kotlin)

```kotlin theme={null}
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.adrop.ads.banner.AdropBanner

class BannerActivity : AppCompatActivity() {
    private lateinit var adropBanner: AdropBanner

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

        // Initialize banner ad
        adropBanner = findViewById(R.id.adrop_banner)
        adropBanner.setUnitId("YOUR_UNIT_ID")

        // Set ad listener (optional)
        adropBanner.listener = object : AdropBannerListener {
            override fun onAdReceived(banner: AdropBanner) {
                // Ad received successfully
            }

            override fun onAdClicked(banner: AdropBanner) {
                // Ad clicked
            }

            override fun onAdFailedToReceive(banner: AdropBanner, errorCode: AdropErrorCode) {
                // Failed to receive ad
            }
        }

        // Load ad
        adropBanner.load()
    }
}
```

**Layout file (activity\_banner.xml)**

```xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <io.adrop.ads.banner.AdropBanner
        android:id="@+id/adrop_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
```

***

### Native Ad (Kotlin)

```kotlin theme={null}
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import io.adrop.ads.nativeAd.AdropNativeAd
import io.adrop.ads.nativeAd.AdropNativeAdView

class NativeAdActivity : AppCompatActivity() {
    private lateinit var nativeAd: AdropNativeAd
    private lateinit var nativeAdView: AdropNativeAdView

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

        // Initialize native ad
        nativeAd = AdropNativeAd(this, "YOUR_UNIT_ID")

        // Set ad listener
        nativeAd.listener = object : AdropNativeAdListener {
            override fun onAdReceived(ad: AdropNativeAd) {
                // Ad received successfully - bind UI
                displayNativeAd(ad)
            }

            override fun onAdClicked(ad: AdropNativeAd) {
                // Ad clicked
            }

            override fun onAdFailedToReceive(ad: AdropNativeAd, errorCode: AdropErrorCode) {
                // Failed to receive ad
            }
        }

        // Load ad
        nativeAd.load()
    }

    private fun displayNativeAd(ad: AdropNativeAd) {
        // Inflate native ad view
        val inflater = LayoutInflater.from(this)
        nativeAdView = inflater.inflate(
            R.layout.native_ad_layout,
            null
        ) as AdropNativeAdView

        // Bind ad elements
        val iconView = nativeAdView.findViewById<ImageView>(R.id.ad_icon)
        val titleView = nativeAdView.findViewById<TextView>(R.id.ad_title)
        val bodyView = nativeAdView.findViewById<TextView>(R.id.ad_body)
        val ctaButton = nativeAdView.findViewById<TextView>(R.id.ad_cta)

        // Set ad data
        // icon is a URL string — use an image loading library
        Glide.with(this).load(ad.icon).into(iconView)
        titleView.text = ad.headline
        bodyView.text = ad.body
        ctaButton.text = ad.callToAction

        // Register ad with native ad view
        nativeAdView.setNativeAd(ad)

        // Add to container
        val adContainer = findViewById<ViewGroup>(R.id.native_ad_container)
        adContainer.removeAllViews()
        adContainer.addView(nativeAdView)
    }

    override fun onDestroy() {
        nativeAd.destroy()
        super.onDestroy()
    }
}
```

**Native ad layout (native\_ad\_layout.xml)**

```xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<io.adrop.ads.nativeAd.AdropNativeAdView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/ad_icon"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignParentStart="true" />

        <TextView
            android:id="@+id/ad_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@id/ad_icon"
            android:layout_marginStart="12dp"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/ad_body"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/ad_title"
            android:layout_toEndOf="@id/ad_icon"
            android:layout_marginStart="12dp"
            android:layout_marginTop="4dp"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/ad_cta"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/ad_body"
            android:layout_alignParentEnd="true"
            android:layout_marginTop="12dp"
            android:background="@drawable/button_background"
            android:padding="12dp"
            android:textColor="@android:color/white"
            android:textSize="14sp"
            android:textStyle="bold" />

    </RelativeLayout>

</io.adrop.ads.nativeAd.AdropNativeAdView>
```

***

### Interstitial Ad (Kotlin)

```kotlin theme={null}
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import io.adrop.ads.interstitial.AdropInterstitialAd

class InterstitialActivity : AppCompatActivity() {
    private var interstitialAd: AdropInterstitialAd? = null
    private lateinit var showButton: Button

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

        showButton = findViewById(R.id.show_interstitial_button)
        showButton.isEnabled = false

        // Load interstitial ad
        loadInterstitialAd()

        showButton.setOnClickListener {
            showInterstitialAd()
        }
    }

    private fun loadInterstitialAd() {
        interstitialAd = AdropInterstitialAd(this, "YOUR_UNIT_ID")

        interstitialAd?.interstitialAdListener = object : AdropInterstitialAdListener {
            override fun onAdReceived(ad: AdropInterstitialAd) {
                // Ad loaded - ready to show
                showButton.isEnabled = true
            }

            override fun onAdFailedToReceive(ad: AdropInterstitialAd, errorCode: AdropErrorCode) {
                // Failed to load ad
                showButton.isEnabled = false
            }

            override fun onAdFailedToShowFullScreen(ad: AdropInterstitialAd, errorCode: AdropErrorCode) {
                // Failed to show ad
            }

            override fun onAdDidPresentFullScreen(ad: AdropInterstitialAd) {
                // Interstitial ad displayed on screen
            }

            override fun onAdDidDismissFullScreen(ad: AdropInterstitialAd) {
                // Interstitial ad closed - load new ad
                loadInterstitialAd()
            }

            override fun onAdClicked(ad: AdropInterstitialAd) {
                // Ad clicked
            }
        }

        interstitialAd?.load()
    }

    private fun showInterstitialAd() {
        interstitialAd?.let { ad ->
            if (ad.isLoaded) {
                ad.show(this@InterstitialActivity)
            }
        }
    }

    override fun onDestroy() {
        interstitialAd?.destroy()
        super.onDestroy()
    }
}
```

***

### Rewarded Ad (Kotlin)

```kotlin theme={null}
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import io.adrop.ads.rewardedAd.AdropRewardedAd

class RewardedAdActivity : AppCompatActivity() {
    private var rewardedAd: AdropRewardedAd? = null
    private lateinit var showButton: Button

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

        showButton = findViewById(R.id.show_rewarded_button)
        showButton.isEnabled = false

        // Load rewarded ad
        loadRewardedAd()

        showButton.setOnClickListener {
            showRewardedAd()
        }
    }

    private fun loadRewardedAd() {
        rewardedAd = AdropRewardedAd(this, "YOUR_UNIT_ID")

        rewardedAd?.rewardedAdListener = object : AdropRewardedAdListener {
            override fun onAdReceived(ad: AdropRewardedAd) {
                // Ad loaded - ready to show
                showButton.isEnabled = true
            }

            override fun onAdFailedToReceive(ad: AdropRewardedAd, errorCode: AdropErrorCode) {
                // Failed to load ad
                showButton.isEnabled = false
            }

            override fun onAdFailedToShowFullScreen(ad: AdropRewardedAd, errorCode: AdropErrorCode) {
                // Failed to show ad
            }

            override fun onAdDidPresentFullScreen(ad: AdropRewardedAd) {
                // Full screen ad displayed
            }

            override fun onAdDidDismissFullScreen(ad: AdropRewardedAd) {
                // Ad closed - load new ad
                loadRewardedAd()
            }

            override fun onAdClicked(ad: AdropRewardedAd) {
                // Ad clicked
            }

            // Note: Reward handling is done via the show() method's second parameter (AdropUserDidEarnRewardHandler)
        }

        rewardedAd?.load()
    }

    private fun showRewardedAd() {
        rewardedAd?.let { ad ->
            if (ad.isLoaded) {
                ad.show(this@RewardedAdActivity) { type, amount ->
                    Toast.makeText(
                        this@RewardedAdActivity,
                        "Reward earned: $amount of type $type",
                        Toast.LENGTH_SHORT
                    ).show()
                    grantReward(type, amount)
                }
            }
        }
    }

    private fun grantReward(type: Int, amount: Int) {
        // Logic to grant reward to user
        // e.g., game coins, lives, items, etc.
    }

    override fun onDestroy() {
        rewardedAd?.destroy()
        super.onDestroy()
    }
}
```

***

## Java Examples

### Banner Ad (Java)

```java theme={null}
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import io.adrop.ads.banner.AdropBanner;

public class BannerActivity extends AppCompatActivity {
    private AdropBanner adropBanner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);

        // Initialize banner ad
        adropBanner = findViewById(R.id.adrop_banner);
        adropBanner.setUnitId("YOUR_UNIT_ID");

        // Set ad listener
        adropBanner.setListener(new AdropBannerListener() {
            @Override
            public void onAdReceived(AdropBanner banner) {
                // Ad received successfully
            }

            @Override
            public void onAdClicked(AdropBanner banner) {
                // Ad clicked
            }

            @Override
            public void onAdFailedToReceive(AdropBanner banner, AdropErrorCode errorCode) {
                // Failed to receive ad
            }
        });

        // Load ad
        adropBanner.load();
    }
}
```

***

### Interstitial Ad (Java)

```java theme={null}
import android.os.Bundle;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import io.adrop.ads.interstitial.AdropInterstitialAd;

public class InterstitialActivity extends AppCompatActivity {
    private AdropInterstitialAd interstitialAd;
    private Button showButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interstitial);

        showButton = findViewById(R.id.show_interstitial_button);
        showButton.setEnabled(false);

        loadInterstitialAd();

        showButton.setOnClickListener(v -> showInterstitialAd());
    }

    private void loadInterstitialAd() {
        interstitialAd = new AdropInterstitialAd(this, "YOUR_UNIT_ID");

        interstitialAd.setInterstitialAdListener(new AdropInterstitialAdListener() {
            @Override
            public void onAdReceived(AdropInterstitialAd ad) {
                showButton.setEnabled(true);
            }

            @Override
            public void onAdFailedToReceive(AdropInterstitialAd ad, AdropErrorCode errorCode) {
                showButton.setEnabled(false);
            }

            @Override
            public void onAdFailedToShowFullScreen(AdropInterstitialAd ad, AdropErrorCode errorCode) {
                // Failed to show ad
            }

            @Override
            public void onAdDidPresentFullScreen(AdropInterstitialAd ad) {
                // Ad displayed
            }

            @Override
            public void onAdDidDismissFullScreen(AdropInterstitialAd ad) {
                // Ad closed - load new ad
                loadInterstitialAd();
            }

            @Override
            public void onAdClicked(AdropInterstitialAd ad) {
                // Ad clicked
            }
        });

        interstitialAd.load();
    }

    private void showInterstitialAd() {
        if (interstitialAd != null && interstitialAd.isLoaded()) {
            interstitialAd.show(this);
        }
    }

    @Override
    protected void onDestroy() {
        if (interstitialAd != null) {
            interstitialAd.destroy();
        }
        super.onDestroy();
    }
}
```

***

## Advanced Examples

### Dark Mode Support

```kotlin theme={null}
import io.adrop.ads.Adrop
import io.adrop.ads.model.AdropTheme

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Set dark mode
        val isDarkMode = resources.configuration.uiMode and
            Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES

        Adrop.setTheme(if (isDarkMode) AdropTheme.DARK else AdropTheme.LIGHT)
    }
}
```

***

### Test Mode

```kotlin theme={null}
import io.adrop.ads.Adrop

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Initialize — use production = false for development/test mode
        Adrop.initialize(this, production = !BuildConfig.DEBUG)
    }
}
```

***

### User Event Tracking

```kotlin theme={null}
import io.adrop.ads.metrics.AdropMetrics
import io.adrop.ads.metrics.AdropEventParam

class EventTrackingActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_event_tracking)

        // Simple event - no parameters
        AdropMetrics.sendEvent("app_open")

        // Event with parameters
        val viewParams = AdropEventParam.Builder()
            .putString("item_id", "SKU-123")
            .putString("item_name", "Widget")
            .putString("item_category", "Electronics")
            .putFloat("price", 29.99f)
            .build()
        AdropMetrics.sendEvent("view_item", viewParams)

        // Multi-item event (purchase)
        val item1 = AdropEventParam.Builder()
            .putString("item_id", "A")
            .putString("item_name", "Product A")
            .putInt("price", 100)
            .putInt("quantity", 1)
            .build()
        val item2 = AdropEventParam.Builder()
            .putString("item_id", "B")
            .putString("item_name", "Product B")
            .putInt("price", 200)
            .putInt("quantity", 2)
            .build()
        val purchaseParams = AdropEventParam.Builder()
            .putString("tx_id", "tx_123")
            .putString("currency", "KRW")
            .putItems(listOf(item1, item2))
            .build()
        AdropMetrics.sendEvent("purchase", purchaseParams)

        // Sign up event
        val signUpParams = AdropEventParam.Builder()
            .putString("method", "google")
            .build()
        AdropMetrics.sendEvent("sign_up", signUpParams)
    }
}
```

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Banner Ads" icon="rectangle-ad" href="/sdk/android/banner">
    Banner ad implementation guide
  </Card>

  <Card title="Native Ads" icon="puzzle-piece" href="/sdk/android/native">
    Native ad implementation guide
  </Card>

  <Card title="Interstitial Ads" icon="expand" href="/sdk/android/interstitial">
    Interstitial ad implementation guide
  </Card>

  <Card title="Rewarded Ads" icon="gift" href="/sdk/android/rewarded">
    Rewarded ad implementation guide
  </Card>
</CardGroup>
