### Create and Load Banner Ad (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration This Kotlin code demonstrates how to create, configure, and load a banner ad. It covers setting ad size, placement name, and implementing an ad listener for various events. The banner view is added to a specified container in your layout. ```kotlin public fun createAndLoadBanner() { // Create ad configuration - optional val adSize = LevelPlayAdSize.BANNER val adConfig = LevelPlayBannerAdView.Config.Builder() .setAdSize(adSize) .setPlacementName("placementName") .build() // Create the banner view and set the ad unit id val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId", adConfig) // Add the banner view to the container val adContainer = findViewById(R.id.adContainer) adContainer.addView(levelPlayBanner) levelPlayBanner.setBannerListener(object: LevelPlayBannerAdViewListener { override fun onAdLoaded(adInfo: LevelPlayAdInfo) { // Ad was loaded successfully } override fun onAdLoadFailed(error: LevelPlayAdError) { // Ad load failed } override fun onAdDisplayed(adInfo: LevelPlayAdInfo) { // Ad was displayed and visible on screen } override fun onAdDisplayFailed(adInfo: LevelPlayAdInfo, error: LevelPlayAdError) { // Ad failed to be displayed on screen } override fun onAdClicked(adInfo: LevelPlayAdInfo) { // Ad was clicked } override fun onAdExpanded(adInfo: LevelPlayAdInfo) { // Ad is opened on full screen } override fun onAdCollapsed(adInfo: LevelPlayAdInfo) { // Ad is restored to its original size } override fun onAdLeftApplication(adInfo: LevelPlayAdInfo) { // User pressed on the ad and was navigated out of the app } }) // Load the banner ad levelPlayBanner.loadAd() // Get width and height for the container val width = adSize.getWidth() val height = adSize.getHeight() } ``` -------------------------------- ### Create and Load Banner Ad (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Use this Java code to create, configure, and load a banner ad. It includes setting ad size, placement name, and handling ad events via a listener. Add the banner view to a container in your layout. ```java public void createAndLoadBanner() { // Create ad configuration - optional LevelPlayAdSize adSize = LevelPlayAdSize.BANNER; LevelPlayBannerAdView.Config adConfig = new LevelPlayBannerAdView.Config.Builder() .setAdSize(adSize) .setPlacementName("placementName") .build(); // Create the banner view and set the ad unit id LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId", adConfig); // Add the banner view to the container ViewGroup adContainer = findViewById(android.R.id.adContainer); adContainer.addView(levelPlayBanner); levelPlayBanner.setBannerListener(new LevelPlayBannerAdViewListener() { @Override public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) { // Ad was loaded successfully } @Override public void onAdLoadFailed(@NonNull LevelPlayAdError error) { // Ad load failed } @Override public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) { // Ad was displayed and visible on screen } @Override public void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) { // Ad failed to be displayed on screen } @Override public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) { // Ad was clicked } @Override public void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) { // Ad is opened on full screen } @Override public void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) { // Ad is restored to its original size } @Override public void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) { // User pressed on the ad and was navigated out of the app } }); // Load the banner ad levelPlayBanner.loadAd(); // To get actual banner layout size (either custom/standard size or adaptive) int height = adSize.getHeight(); int width = adSize.getWidth(); } ``` -------------------------------- ### Create Adaptive Ad Size (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Create an adaptive ad size that automatically adjusts to the screen width and device type for optimal banner display. ```java LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context); ``` -------------------------------- ### Create Adaptive Ad Size (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Create an adaptive ad size that automatically adjusts to the screen width and device type for optimal banner display. ```kotlin val adSize = createAdaptiveAdSize(context) ``` -------------------------------- ### Create Banner Ad Object (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Create a banner ad object after the SDK initialization callback. Use this to set ad size and placement name. ```kotlin val adSize = LevelPlayAdSize.BANNER val adConfig = LevelPlayBannerAdView.Config.Builder() .setAdSize(adSize) .setPlacementName("placementName") .build() val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId", adConfig) ``` -------------------------------- ### Create Banner Ad Object (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Create a banner ad object after the SDK initialization callback. Use this to set ad size and placement name. ```java LevelPlayAdSize adSize = LevelPlayAdSize.BANNER; LevelPlayBannerAdView.Config adConfig = new LevelPlayBannerAdView.Config.Builder() .setAdSize(adSize) .setPlacementName("placementName") .build(); LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId", adConfig); ``` -------------------------------- ### Load Banner Ad Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Use the `loadAd()` method to load a banner ad. This is the initial step before displaying the ad. ```java // Load the banner ad levelPlayBanner.loadAd(); ``` ```kotlin // Load the banner ad levelPlayBanner.loadAd() ``` -------------------------------- ### Set Banner Listener in Java Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Implement the LevelPlayBannerAdViewListener to receive ad events. Set the listener before loading the ad. Callbacks run on the main thread. ```java levelPlayBanner.setBannerListener(new LevelPlayBannerAdViewListener() { @Override public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) { // Ad was loaded successfully } @Override public void onAdLoadFailed(@NonNull LevelPlayAdError error) { // Ad load failed } @Override public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) { // Ad was displayed and visible on screen } @Override public void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) { // Optional. Ad failed to be displayed on screen } @Override public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) { // Ad was clicked } @Override public void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) { // Optional. Ad is opened on full screen } @Override public void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) { // Optional. Ad is restored to its original size } @Override public void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) // Optional. User pressed on the ad and was navigated out of the app } }); ``` -------------------------------- ### Set Placement Name (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Set the placement name for banner ads. This is used for reporting purposes and should be set before loading ads. ```kotlin // Set the placement name levelPlayBanner.setPlacementName("placementName") ``` -------------------------------- ### Set Placement Name (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Set the placement name for banner ads. This is used for reporting purposes and should be set before loading ads. ```java // Set the placement name levelPlayBanner.setPlacementName("placementName"); ``` -------------------------------- ### Set Banner Listener in Kotlin Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Implement the LevelPlayBannerAdViewListener to receive ad events. Set the listener before loading the ad. Callbacks run on the main thread. ```kotlin levelPlayBanner.setBannerListener(object: LevelPlayBannerAdViewListener { override fun onAdLoaded(adInfo: LevelPlayAdInfo) { // Ad was loaded successfully } override fun onAdLoadFailed(error: LevelPlayAdError) { // Ad load failed } override fun onAdDisplayed(adInfo: LevelPlayAdInfo) { // Ad was displayed and visible on screen } override fun onAdDisplayFailed(adInfo: LevelPlayAdInfo, error: LevelPlayAdError) { // Optional. Ad failed to be displayed on screen } override fun onAdClicked(adInfo: LevelPlayAdInfo) { // Ad was clicked } override fun onAdExpanded(adInfo: LevelPlayAdInfo) { // Optional. Ad is opened on full screen } override fun onAdCollapsed(adInfo: LevelPlayAdInfo) { // Optional. Ad is restored to its original size } override fun onAdLeftApplication(adInfo: LevelPlayAdInfo) { // Optional. User pressed on the ad and was navigated out of the app } }) ``` -------------------------------- ### Load Banner Ad Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration To load a banner ad use the loadAd method. ```APIDOC ## Load Banner Ad To load a banner ad use **loadAd**. ```java // Load the banner ad levelPlayBanner.loadAd(); ``` ```kotlin // Load the banner ad levelPlayBanner.loadAd() ``` ``` -------------------------------- ### Set Specific Banner Size (Kotlin) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Set a specific banner size such as BANNER, LARGE, or MEDIUM_RECTANGLE for the banner ad. ```kotlin levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE) ``` -------------------------------- ### Set Specific Banner Size (Java) Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Set a specific banner size such as BANNER, LARGE, or MEDIUM_RECTANGLE for the banner ad. ```java levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE); ``` -------------------------------- ### Pause and Resume Banner Refresh Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Control automatic banner ad refresh using `pauseAutoRefresh()` and `resumeAutoRefresh()`. When resumed, the banner completes its refresh cycle from the time it was paused. ```java // Pause refresh levelPlayBanner.pauseAutoRefresh(); // Resume refresh levelPlayBanner.resumeAutoRefresh(); ``` ```kotlin // Pause refresh levelPlayBanner.pauseAutoRefresh() // Resume refresh levelPlayBanner.resumeAutoRefresh() ``` -------------------------------- ### Destroy Banner Ad Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration To destroy a banner, call the destroy method. A destroyed banner can no longer be shown. To display more ads, create a new LevelPlayBannerAdView object. ```APIDOC ## Destroy Banner Ad To destroy a banner, call the **destroy** method. A destroyed banner can no longer be shown again. To display more ads, create a new **LevelPlayBannerAdView** object. ```java levelPlayBanner.destroy() ``` ```kotlin levelPlayBanner.destroy(); ``` ``` -------------------------------- ### Pause and Resume Banner Refresh Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration You can pause banner refresh if the refresh value was defined in the platform. Use pauseAutoRefresh to stop and resumeAutoRefresh to re-enable automatic refresh. ```APIDOC ## Pause and Resume Banner Refresh You can pause banner refresh in your code if the refresh value was defined in the platform. Use the following methods to stop the automatic refresh of the banner ad, or re-enable it after pausing. > **Note:** > > When the banner is displayed again, it will complete the time until refresh from the time it was paused. * **pauseAutoRefresh** - pauses auto-refresh of the banner ad. * **resumeAutoRefresh** - resumes auto-refresh of the banner ad after it has been paused. ```java // Pause refresh levelPlayBanner.pauseAutoRefresh(); // Resume refresh levelPlayBanner.resumeAutoRefresh(); ``` ```kotlin // Pause refresh levelPlayBanner.pauseAutoRefresh() // Resume refresh levelPlayBanner.resumeAutoRefresh() ``` ``` -------------------------------- ### Destroy Banner Ad Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/banner-integration Call the `destroy()` method to permanently remove a banner ad. A destroyed banner cannot be shown again; a new `LevelPlayBannerAdView` must be created for subsequent ads. ```java levelPlayBanner.destroy() ``` ```kotlin levelPlayBanner.destroy(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.