Native (Google)

The native ads are a kind of ad that can be shown using the same visual style like the rest of the app, which allows a natural and non-intrusive integration with the user interface.

Currently, Wortise provides the possibility of use the native ads from Google's ad platform ("Native Advanced"), in a simple and direct way.

Integration

To request a native ad, it is needed to make an integration by code just as shown in the example below:

public class MainActivity extends Activity {

    private GoogleNativeAd mGoogleNativeAd;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        mGoogleNativeAd = new GoogleNativeAd(
                this, "Wortise Ad Unit ID", mNativeListener);
        mGoogleNativeAd.load();
    }
    
    @Override
    public void onDestroy() {
        ...
        mGoogleNativeAd.destroy();
    }
    
    private GoogleNativeAd.Listener mNativeListener 
            = new GoogleNativeAd.Listener() {
            
        @Override
        public void onNativeClicked(@NonNull GoogleNativeAd ad) {
            // Invoked when ad has been clicked
        }
        
        @Override
        public void onNativeFailedToLoad(@NonNull GoogleNativeAd ad,
                                         @NonNull AdError error) {
            // Invoked when the ad could not be loaded
            // (because of an error or no fill)
        }
        
        @Override
        public void onNativeImpression(@NonNull GoogleNativeAd ad) {
            // Invoked when the ad has generated an impression
        }
        
        @Override
        public void onNativeLoaded(@NonNull GoogleNativeAd ad,
                                   @NonNull NativeAd nativeAd) {
            // Invoked when the ad has been loaded
        }
    }
}

Once the native ad has been successfully loaded, obtaining as result a NativeAd instance, it is needed to complete the integration by following Google's documentation on this matter: https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/advanced?hl=en#display_a_nativead

Specify options

The GoogleNativeAd class includes a method called withNativeAdOptions which allows to specify custom options by using the NativeAdOptions class from Google. This method must be called before loading the ad.

Below you can check a brief usage example:

NativeAdOptions adOptions = new NativeAdOptions.Builder()
        ...
        .build();

mGoogleNativeAd.withNativeAdOptions(adOptions);

Última actualización