### Initialize FairBid SDK Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Initialize and start the FairBid SDK in your main activity. Ensure you replace the placeholder app ID with your actual ID from the Fyber console. The SDK requires this configuration before any ad operations. ```kotlin import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.fyber.FairBid class MainActivity : AppCompatActivity() { companion object { // Replace with your own app id from Fyber console private const val PUBLISHERS_APP_ID = "109613" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Initialize and start the FairBid SDK startFairBidSdk(PUBLISHERS_APP_ID) } private fun startFairBidSdk(appId: String) { val fairBid = FairBid.configureForAppId(appId).enableLogs() fairbid.start(this) } } ``` -------------------------------- ### Configure Gradle Build Dependencies Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Apply the FairBid SDK plugin and define necessary Android dependencies in the build.gradle file. ```groovy plugins { id 'com.fyber.fairbid-sdk-plugin' id 'com.android.application' id 'kotlin-android' } android { compileSdkVersion 36 namespace 'com.fyber.fairbid.sample' defaultConfig { applicationId "com.fyber.fairbid.sample" minSdkVersion 19 targetSdkVersion 36 versionCode 1 versionName "1.0" // Required when including multiple mediated networks multiDexEnabled true } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.10" implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' // Required when including multiple mediated networks implementation 'androidx.multidex:multidex:2.0.1' } ``` -------------------------------- ### Display and Configure Banner Ads Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Display banner ads using the `Banner.show` method. You can customize placement and size (e.g., `BannerSize.SMART` or `BannerSize.MREC`). Remember to destroy banners when they are no longer needed to free up resources. ```kotlin import android.app.Activity import android.view.ViewGroup import com.fyber.fairbid.ads.Banner import com.fyber.fairbid.ads.banner.BannerOptions import com.fyber.fairbid.ads.banner.BannerSize // Placement names configured in Fyber console private const val BANNER_PLACEMENT_NAME = "197407" private const val MREC_PLACEMENT_NAME = "936586" // Display a banner ad in a container fun displayBanner(placementName: String, bannerContainer: ViewGroup, activity: Activity) { val bannerOptions = BannerOptions() .placeInContainer(bannerContainer) .withSize(BannerSize.SMART) // Use BannerSize.MREC for medium rectangle Banner.show(placementName, bannerOptions, activity) } // Destroy a banner when no longer needed fun destroyBanner(placementName: String) { Banner.destroy(placementName) } ``` -------------------------------- ### Show FairBid Test Suite Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Display the FairBid Test Suite for debugging and validating ad integrations. This function requires an Activity context. You can also access the SDK version via the `SDK_VERSION` constant. ```kotlin import android.app.Activity import com.fyber.FairBid // Show the test suite for debugging ad integrations fun showTestSuite(activity: Activity) { FairBid.showTestSuite(activity) } // Get SDK version val sdkVersion = FairBid.SDK_VERSION ``` -------------------------------- ### Handle Banner Ad Events Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Implement the `BannerListener` interface to receive callbacks for banner ad lifecycle events such as load, show, click, and errors. Ensure you register this listener before making ad requests. ```kotlin import com.fyber.fairbid.ads.Banner import com.fyber.fairbid.ads.ImpressionData import com.fyber.fairbid.ads.banner.BannerError import com.fyber.fairbid.ads.banner.BannerListener fun setBannerListener() { val bannerListener = object : BannerListener { override fun onShow(placement: String, impressionData: ImpressionData) { // Called when the banner is displayed Log.d("Banner", "Banner shown for placement: $placement") } override fun onRequestStart(placement: String, requestId: String) { // Called when a banner request starts Log.d("Banner", "Request started: $placement - $requestId") } override fun onClick(placement: String) { // Called when the banner is clicked Log.d("Banner", "Banner clicked: $placement") } override fun onLoad(placement: String) { // Called when the banner is loaded and ready Log.d("Banner", "Banner loaded: $placement") } override fun onError(placement: String, error: BannerError) { // Called when an error occurs Log.e("Banner", "Error: ${error.errorMessage}") } } Banner.setBannerListener(bannerListener) } ``` -------------------------------- ### Implement Rewarded Ad Listener in Kotlin Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Use the RewardedListener interface to handle ad lifecycle events and grant rewards upon successful completion. ```kotlin import com.fyber.fairbid.ads.Rewarded import com.fyber.fairbid.ads.ImpressionData import com.fyber.fairbid.ads.rewarded.RewardedListener fun setRewardedListener() { val rewardedListener = object : RewardedListener { override fun onShow(placement: String, impressionData: ImpressionData) { Log.d("Rewarded", "Ad shown: $placement") } override fun onShowFailure(placement: String, impressionData: ImpressionData) { Log.e("Rewarded", "Show failed: $placement") } override fun onRequestStart(placement: String, requestId: String) { Log.d("Rewarded", "Request started: $placement - $requestId") } override fun onClick(placement: String) { Log.d("Rewarded", "Ad clicked: $placement") } override fun onHide(placement: String) { Log.d("Rewarded", "Ad hidden: $placement") } override fun onAvailable(placement: String) { // Ad is ready to be shown Log.d("Rewarded", "Ad available: $placement") } override fun onUnavailable(placement: String) { // No ad available for this placement Log.d("Rewarded", "Ad unavailable: $placement") } override fun onCompletion(placement: String, userRewarded: Boolean) { // Grant reward to user if userRewarded is true if (userRewarded) { Log.d("Rewarded", "User earned reward for: $placement") // Grant in-app reward here } else { Log.d("Rewarded", "User did not earn reward: $placement") } } } Rewarded.setRewardedListener(rewardedListener) } ``` -------------------------------- ### Request and Display Interstitial Ads Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Use these functions to request an interstitial ad, show it when available, and check its readiness. Ensure an ad is not already available before requesting. ```kotlin import android.app.Activity import com.fyber.fairbid.ads.Interstitial private const val INTERSTITIAL_PLACEMENT_NAME = "197405" // Request an interstitial ad fun requestInterstitial(placementName: String) { // Only request if no ad is already available if (!Interstitial.isAvailable(placementName)) { Interstitial.request(placementName) } } // Show the interstitial ad when available fun showInterstitial(placementName: String, activity: Activity?) { Interstitial.show(placementName, activity) } // Check if an interstitial ad is available fun isInterstitialReady(placementName: String): Boolean { return Interstitial.isAvailable(placementName) } ``` -------------------------------- ### Request and Display Rewarded Ads Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Functions to request, display, and check the availability of rewarded video ads. Similar to interstitials, avoid requesting if an ad is already available. ```kotlin import android.app.Activity import com.fyber.fairbid.ads.Rewarded private const val REWARDED_PLACEMENT_NAME = "197406" // Request a rewarded ad fun requestRewarded(placementName: String) { // Only request if no ad is already available if (!Rewarded.isAvailable(placementName)) { Rewarded.request(placementName) } } // Show the rewarded ad when available fun showRewarded(placementName: String, activity: Activity?) { Rewarded.show(placementName, activity) } // Check if a rewarded ad is available fun isRewardedReady(placementName: String): Boolean { return Rewarded.isAvailable(placementName) } ``` -------------------------------- ### Handle Interstitial Ad Events Source: https://context7.com/fyber-engineering/fairbid-sample-app-android/llms.txt Implement the InterstitialListener to receive callbacks for ad events such as showing, clicking, hiding, and availability changes. Log relevant information for each event. ```kotlin import com.fyber.fairbid.ads.Interstitial import com.fyber.fairbid.ads.ImpressionData import com.fyber.fairbid.ads.interstitial.InterstitialListener import android.util.Log fun setInterstitialListener() { val interstitialListener = object : InterstitialListener { override fun onShow(placement: String, impressionData: ImpressionData) { Log.d("Interstitial", "Ad shown: $placement") } override fun onShowFailure(placement: String, impressionData: ImpressionData) { Log.e("Interstitial", "Show failed: $placement") } override fun onRequestStart(placement: String, requestId: String) { Log.d("Interstitial", "Request started: $placement - $requestId") } override fun onClick(placement: String) { Log.d("Interstitial", "Ad clicked: $placement") } override fun onHide(placement: String) { Log.d("Interstitial", "Ad hidden: $placement") } override fun onAvailable(placement: String) { // Ad is ready to be shown Log.d("Interstitial", "Ad available: $placement") } override fun onUnavailable(placement: String) { // No ad available for this placement Log.d("Interstitial", "Ad unavailable: $placement") } } Interstitial.setInterstitialListener(interstitialListener) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.