Native Ads | Android

Native ads are designed to respond exactly to your needs. With native ads, you are able to show ads in your apps that look the same as your app content. That means more control, a better-fitting design, improved user experience, and of course more revenue.

The Smaato Native Ads Serving Template (SNAST) gives you the flexibility to choose which elements you need for your ad space. Currently, we have the following items available:

  • Ad title
  • Ad text
  • Icon Image (80×80 pixels)
  • Main Image (1200×627 pixels)
  • Click to install text (e.g. Install, Read More etc…)
  • Star rating (only for app ads)

In order to start using native ads, you will need to follow these steps:

  1. Create all needed views (icon view, main image view, text views, rating bar etc…)
  2. Put your views together so that they look similar to your app content
  3. Pass the views to our SDK
  4. Finally, start requesting

 

1) After you have created all of the views, please proceed by passing the views to our SDK by using the following code:

NativeAd nativeAd = new NativeAd(this);
nativeAd.setClickToActionButton(ctaButton).setIconImageView(iconImage)
                .setMainImageView(mainImage).setTextView(nativeText)
                .setTitleView(nativeTitle).setMainLayout(nativeRelativeLayout).setRatingBar(ratingBar);

2) You then can start requesting ads by using the following method:

nativeAd.asyncLoadNewBanner();

3) After receiving the rendered Native Ad, you need to attach the native ad components and make them visible:

iconImage.setVisibility(View.VISIBLE);
mainImage.setVisibility(View.VISIBLE);
nativeText.setVisibility(View.VISIBLE);
ctaButton.setVisibility(View.VISIBLE);
nativeTitle.setVisibility(View.VISIBLE);
nativeRelativeLayout.setVisibility(View.VISIBLE);
ratingBar.setVisibility(View.VISIBLE);
 
// IMPORTANT step to be invoked after attaching the NativeAd. (SDK checks the native ad component visibility before firing Impression).
// IMPORTANT FOR IMPRESSIONS COUNTS & REVENUE.
nativeAd.registerImpression();

3) You can also be notified to know if we delivered an ad or not. To activate that, please let your activity implement our AdListenerInterface. Below is a sample code:

public class MyActivity implements AdListenerInterface

4) Lastly, do not forget to register the listener by using the following code:

nativeAd.setAdListener(MyActivity.this);
 

 

Native Ad Templates

To start using Native Ad Templates, you will need to go through the following steps:

  1. Create a RelativeLayout and set it as MainLayout.
  2. Set the params (width & height without density, text size) to look similar to your App.
  3. Pass the NativeType to Smaato SDK and load new Ad.
  4. With a successful Ad response, the generated NativeLayout (RelativeLayout) will be available with its elements based on the NativeType (TitleView, RatingStar, Click to Action Button, Icon).
// Step 1:Declare properties
NativeAd nativeAd;
RelativeLayout nativeRelativeLayout;
 
// Step 2: Instantiate & Configure mandatory parameters
nativeAd = new NativeAd(this);
nativeRelativeLayout = (RelativeLayout) findViewById(R.id.nativeAdLayout);
nativeAd.setMainLayout(nativeRelativeLayout);
nativeAd.getAdSettings().setPublisherId(0);  // replace with your PublisherId
nativeAd.getAdSettings().setAdspaceId(3075); // replace with your AdSpaceId
 
// Following are non mandatory formatting as per your app (look and feel) requirements.
nativeAd.setTitleTextSize(15);
nativeAd.setWidthWithoutDensity(80);  // density calculation happens inside SDK for icons width
nativeAd.setHeightWithoutDensity(80); // default value is 70*density
 
// Step 3: Initiate new ad request by sending required NativeType and attach the Ad response using nativeAd.bindAdResponse(nativeView); 
 nativeAd.asyncLoadNativeType(NativeAd.NativeType.APP_WALL, new NativeAd.NativeAdTypeListener() {
   @Override
   public void onError(ErrorCode errorCode, String errorMessage) {      
      Log.e("OnErrorResponse", errorMessage); // No Ad Response is fine. Check for errorCode & errorMessage.
   }

    @Override
   public void onAdResponse(ViewGroup createdNativeLayout) {
         // if required, configure & format individual element of the generated Layout element before binding.
         //nativeAd.getIconImageView().setBackgroundColor(Color.BLUE); 
         nativeAd.getTitleView().setTextColor(Color.BLUE);
         // IMPORTANT FOR IMPRESSION COUNT & BEACONS. Invoke bindAdResponse only after attaching mainLayout with visibility (VISIBLE).
         nativeAd.bindAdResponse(createdNativeLayout);
      }
});

Integrating other Templates

These implementation steps are similar for all other Native Layout Types. Please Aware that Native Carousel supports an ArrayList of ImageViews and is accessible through nativeAd.getCarouselImages().

Send the required NativeType to the method nativeAd.asyncLoadNativeType

Please Note: The SmaatoDemoApp has sample implementations of all the NativeLayouts.

Modified: August 30, 2019 at 2:45 pm