### Load Native Ad with LevelPlay SDK Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/native-ads-integration Use LevelPlayNativeAd.Builder to create and configure a native ad object. Ensure SDK initialization is complete before loading. Remember to destroy the ad object and create a new one for each subsequent load. ```java LevelPlayNativeAd nativeAd = new LevelPlayNativeAd.Builder() .withPlacementName(placementName) .withListener(listener) .build(); // You can add the native ad object to a list of native ads (mNativeAds), which can be used to display the ad when needed mNativeAds.add(nativeAd); nativeAd.loadAd(); ``` -------------------------------- ### Implement Native Ad Listener Callbacks Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/native-ads-integration Implement the `LevelPlayNativeAdListener` to receive callbacks for native ad events such as loading, failure, impression, and clicks. Your implementation should handle these events appropriately. ```java // Invoked each time a native ad was loaded. @Override public void onAdLoaded(LevelPlayNativeAd nativeAd, AdInfo adInfo) { // Your implementation here } // Invoked when the native ad loading process has failed. @Override public void onAdLoadFailed(LevelPlayNativeAd nativeAd, IronSourceError error) { // Your implementation here } // Invoked each time the first pixel is visible on the screen @Override public void onAdImpression(LevelPlayNativeAd nativeAd, AdInfo adInfo) { // Your implementation here } // Invoked when end user clicked on the native ad @Override public void onAdClicked(LevelPlayNativeAd nativeAd, AdInfo adInfo) { // Your implementation here } ``` -------------------------------- ### Populate and Register Native Ad Views Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/native-ads-integration Locates, populates, and registers views for native ad assets (title, icon, media, CTA) with the `NativeAdLayout`. This ensures the ad's data is correctly displayed. ```java // Locate all views to be populated TextView titleView = nativeAdLayout.findViewById(R.id.ad_title); ImageView iconView = nativeAdLayout.findViewById(R.id.ad_app_icon); LevelPlayMediaView mediaView = nativeAdLayout.findViewById(R.id.ad_media); // Populate the views String title = nativeAd.getTitle(); if (title != null) { titleView.setText(title); } NativeAdDataInterface.Image icon = nativeAd.getIcon(); if (icon != null) { if (icon.getDrawable() != null) { iconView.setImageDrawable(icon.getDrawable()); } } // Register the views to be bound nativeAdLayout.setTitleView(titleView); nativeAdLayout.setIconView(iconView); nativeAdLayout.setMediaView(mediaView); nativeAdLayout.setCallToActionView(ctaView); // Register the native ad with the layout nativeAdLayout.registerNativeAdViews(nativeAd); ``` -------------------------------- ### XML Layout for NativeAdLayout Source: https://docs.unity.com/en-us/grow/levelplay/sdk/android/native-ads-integration A sample XML layout structure for `NativeAdLayout`. This defines the visual elements of a native ad, including title, icon, call to action, and other assets. ```xml