Loading ads

  1. Decide how to load images for showing ads. Images can be loaded automatically or manually. The method for uploading images is set using the shouldLoadImagesAutomatically() parameter for the Builder method.
  2. Create the adLoaderConfiguration using the NativeAdLoaderConfiguration class. When initializing an instance of this class, pass the required parameters: blockID and shouldLoadImagesAutomatically.
    final NativeAdLoaderConfiguration adLoaderConfiguration =
                    new NativeAdLoaderConfiguration.Builder("R-M-DEMO-native-c", true).build();
    Block ID is a unique identifier in the adf-XXXXXX/YYYYYY format, which is assigned in the Partner interface.
    Attention.

    In the mobile mediation interface, the Block ID is called the location ID.

  3. Optionally set preferred image size classes. Each class corresponds to a specific set of image formats. Sizes are set using the setImageSizes method.
    final NativeAdLoaderConfiguration adLoaderConfiguration =
                    new NativeAdLoaderConfiguration.Builder("R-M-DEMO-native-c", true)
                            .setImageSizes(NativeAdLoaderConfiguration.NATIVE_IMAGE_SIZE_MEDIUM).build();
    Note.

    By default, all image size classes are requested. This means that any size of image can be included in the response from the SDK.

    // BLOCK_ID — A unique identifier assigned in the Partner interface.
    // shouldLoadImagesAutomatically — Indicates whether to automatically load images.
    final NativeAdLoaderConfiguration adLoaderConfiguration =
        new NativeAdLoaderConfiguration.Builder(BLOCK_ID, shouldLoadImagesAutomatically).setImageSizes(NATIVE_IMAGE_SIZE_MEDIUM, NATIVE_IMAGE_SIZE_LARGE).build();
    Image classes and formats
    NATIVE_IMAGE_SIZE_SMALL class
    Fixed size Allowed height to width ratio Description
    Height — 150 pixels
    • 1:1
    • 3:4
    • 4:3
    • 16:9
    A small image that is positioned next to the ad.
    NATIVE_IMAGE_SIZE_MEDIUM
    Fixed size Allowed height to width ratio Description
    Width — 600 pixels
    • 16:9
    A medium-sized image that is positioned next to the ad.
    Width — 450 pixels
    • 1:1
    • 3:4
    • 4:3
    • 16:9
    Height — 450 pixels
    • 1:1
    • 3:4
    • 4:3
    • 16:9
    Width — 300 pixels
    • 16:9
    NATIVE_IMAGE_SIZE_LARGE class
    Fixed size Allowed height to width ratio Description
    Width — 1080 pixels
    • 16:9
    A large image that is positioned:
    • in the center of the ad and covers the entire width of the ad or most of the width.
    • at the bottom of the ad and covers the entire width of the ad or most of the width.
    Width — 600 pixels
    • 16:9
    Height — 450 pixels
    • 1:1
    • 3:4
    • 4:3
    • 16:9
  4. Use the NativeAdLoader class to create a loader for native ads. Pass an instance of the adLoaderConfiguration class as a parameter.
    mNativeAdLoader = new NativeAdLoader(getApplicationContext(), adLoaderConfiguration);
  5. To get native ads, set NativeAdLoader.OnImageAdLoadListener for the NativeAdLoader instance.
    mNativeAdLoader.setOnLoadListener(new NativeAdLoader.OnImageAdLoadListener() {
          @Override
          public void onImageAdLoaded(@NonNull final NativeImageAd nativeImageAd) {
                ...
           }
          ...
    });
  6. To track the ad loading process, implement the NativeAdLoader.OnLoadListener interface methods: onAdFailedToLoad, onAppInstallAdLoaded, onContentAdLoaded and the onImageAdLoaded method of the NativeAdLoader.OnImageAdLoadListener interface.
  7. To load an ad, call the loadAd method of the NativeAdLoader class. Pass an instance of the AdRequest class as a parameter.
    mNativeAdLoader.loadAd(AdRequest.builder().build());
  8. If the ad loaded, the onAppInstallAdLoaded, onContentAdLoaded, or onImageAdLoaded methods will be called. If the ad didn't load, onAdFailedToLoad is called.

Ways to load images

If the app simultaneously stores links to just one or a small number of ads, we recommend using automatic loading.

When creating the configuration, set shouldLoadImagesAutomatically to true:

final NativeAdLoaderConfiguration adLoaderConfiguration =
    new NativeAdLoaderConfiguration.Builder(BLOCK_ID, shouldLoadImagesAutomatically).setImageSizes(NATIVE_IMAGE_SIZE_MEDIUM, NATIVE_IMAGE_SIZE_LARGE).build();

The resulting ad will have the images ready. They are stored in the device memory until the ad is destroyed.

Notifications about image loading

Restriction. You can only get notifications when loading images manually.

To enable notifications that are sent when an image is loaded, call the addImageLoadingListener method:

nativeAd.addImageLoadingListener(new NativeAdImageLoadingListener() {
       @Override
       public void onFinishLoadingImages() {
              ...
       }
});