Native Ad Templates

Add IkmWidgetAdView to the Layout

The first step in displaying a native ad is to place an IkmWidgetAdView in the layout for the Activity or Fragment where the ad is to be shown.

  <com.ikame.android.sdk.widgets.IkmWidgetAdView
    android:id="@+id/adsView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:ikwad_preview_layout="@layout/shimmer_loading_native" />
  

Load an ad with Templates

To simplify native ad integration, the SDK provides three pre-defined types of native ad: NORMAL_LAYOUT, EXIT_LAYOUT, and BANNER_LAYOUT. These templates allow for quick and flexible integration of native ads in different parts of your application.

To load a native ad with a specific template, call the IkmWidgetAdView loadAd() method. You need to pass the ad unit ID (screen), the desired native template (IKNativeTemplate), and an IKShowWidgetAdListener to handle the ad events, including success or error states.

Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#loadAd(String, IKNativeTemplate, IKShowWidgetAdListener)
  

Function Definition

  fun loadAd(
    screen: String,
    template: IKNativeTemplate,
    listener: IKShowWidgetAdListener?
)
  

Parameters:

  • screen: considered as a unitId, our team will send you the screenAd list.
  • template: IKNativeTemplate Enum - Defines templates for native advertising, specifying layout and style configurations to be used within the application.
  • listener: IKShowWidgetAdListener Interface - Manages callbacks for displaying widget ads, focusing on events for ad load success and failures.

Sample Usage

Load and save special native adObject

Load native adObject

This will return an IkmDisplayWidgetAdView for displaying the ad.

Reference

  com.ikame.android.sdk.IKSdkController#loadNativeDisplayAd
  

Function Definition

  fun loadNativeDisplayAd(
    screen: String,
    callback: IKLoadDisplayAdViewListener?
)
  

Parameters:

  • screen: String - The ad unit ID that specifies which native display ad to load. This ID is used to identify and fetch the appropriate ad from the server.
  • callback: IKLoadDisplayAdViewListener Interface - Handles callbacks related to the loading of display ad views, with attention to the completion of ad loads and error handling.

Sample Usage

Show special adObject with Templates

Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#showWithDisplayAdView(String, String, IKNativeTemplate, IkmDisplayWidgetAdView, IKShowWidgetAdListener)
  

Function Definition

  fun showWithDisplayAdView(
    screen: String,
    template: IKNativeTemplate,
    displayWidgetAdView: IkmDisplayWidgetAdView,
    adListener: IKShowWidgetAdListener?
)
  

Parameters

  • screen: considered as a unitId, our team will send you the screenAd list.
  • template: IKNativeTemplate Enum - Defines templates for native advertising, specifying layout and style configurations to be used within the application.
  • displayWidgetAdView: IkmDisplayWidgetAdView - The view object used to display the native ad. This view should be configured to handle the ad content according to the chosen template.
  • listener: IKShowWidgetAdListener Interface - Manages callbacks for displaying widget ads, focusing on events for ad load success and failures.

Sample Usage

Native Ad Custom

Add IkmWidgetAdView to the Layout

The first step in displaying a native ad is to place an IkmWidgetAdView in the layout for the Activity or Fragment where the ad is to be shown.

  <com.ikame.android.sdk.widgets.IkmWidgetAdView
    android:id="@+id/adsView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:ikwad_preview_layout="@layout/shimmer_loading_native" />
  

Load an ad with Custom Layout

This method allows for loading an ad with a custom layout specified by the developer.The loadAd() function in the IkmWidgetAdView class allows you to load a native ad with a shimmer layout, a specific ad layout (IkmWidgetAdLayout), and an ad screen ID. This method enables the integration of native ads with custom loading animations (shimmer effects) while ensuring the ad is displayed within the provided layout.

Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#loadAd(int, IkmWidgetAdLayout, String, String, IKShowWidgetAdListener)
  

Function Definition

  fun loadAd(
    @LayoutRes layoutShimmerRes: Int,
    layoutAd: IkmWidgetAdLayout,
    screen: String,
    listener: IKShowWidgetAdListener?
)
  

Parameters:

  • layoutShimmerRes: The resource ID of the shimmer layout that will be shown while the ad is loading. This allows you to create a smooth loading experience for the user.
  • layoutAd: The specific IkmWidgetAdLayout for rendering the native ad. This layout determines how the ad will be displayed in the UI.
  • screen: considered as a unitId, our team will send you the screenAd list.
  • listener: IKShowWidgetAdListener Interface - Manages callbacks for displaying widget ads, focusing on events for ad load success and failures.

Sample Usage

layout_custom_admob

Load and save special native adObject

Load native adObject

This will return an IkmDisplayWidgetAdView for displaying the ad.

Reference

  com.ikame.android.sdk.IKSdkController#loadNativeDisplayAd
  

Function Definition

  fun loadNativeDisplayAd(
    screen: String,
    callback: IKLoadDisplayAdViewListener?
)
  

Parameters:

  • screen: String - The ad unit ID that specifies which native display ad to load. This ID is used to identify and fetch the appropriate ad from the server.
  • callback: IKLoadDisplayAdViewListener Interface - Handles callbacks related to the loading of display ad views, with attention to the completion of ad loads and error handling.

Sample Usage

Show special adObject with Templates

Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#showWithDisplayAdView(String, String, IKNativeTemplate, IkmDisplayWidgetAdView, IKShowWidgetAdListener)
  

Function Definition

  fun showWithDisplayAdView(
    screen: String,
    template: IKNativeTemplate,
    displayWidgetAdView: IkmDisplayWidgetAdView,
    adListener: IKShowWidgetAdListener?
)
  

Parameters

  • screen: considered as a unitId, our team will send you the screenAd list.
  • template: IKNativeTemplate Enum - Defines templates for native advertising, specifying layout and style configurations to be used within the application.
  • displayWidgetAdView: IkmDisplayWidgetAdView - The view object used to display the native ad. This view should be configured to handle the ad content according to the chosen template.
  • listener: IKShowWidgetAdListener Interface - Manages callbacks for displaying widget ads, focusing on events for ad load success and failures.

Sample Usage

Full-screen native ad

Add IkmWidgetAdView to the Layout

The first step in displaying a native ad is to place an IkmWidgetAdView in the layout for the Activity or Fragment where the ad is to be shown.

  <com.ikame.android.sdk.widgets.IkmWidgetAdView
    android:id="@+id/adsView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:ikwad_preview_layout="@layout/shimmer_loading_native" />
  

Load an ad with full-screen native layout

The loadAd() function in the IkmWidgetAdView class allows you to load a native ad with a shimmer layout, a specific ad layout (IkmWidgetAdLayout), and an ad screen ID. This method enables the integration of native ads with custom loading animations (shimmer effects) while ensuring the ad is displayed within the provided layout. Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#loadAdFS( IkmWidgetAdLayout, String, IKShowWidgetAdListener)
  

Function Definition

  fun loadAdFS(
    layoutAd: IkmWidgetAdLayout,
    screen: String,
    callback: IKShowWidgetAdListener?
)
  

Parameters:

  • layoutAd: The specific IkmWidgetAdLayout for rendering the full-screen native ad. This layout determines how the ad will be displayed in the UI.
  • screen: considered as a unitId, our team will send you the screenAd list.
  • listener: IKShowWidgetAdListener Interface - Manages callbacks for displaying widget ads, focusing on events for ad load success and failures.

By default, ads with any aspect ratio can be returned. Based on that, our SDK will automatically divide into 3 types: NORMAL, SQUARE, and PORTRAIT, so in the layout of full-screen native ads, there will also be 3 layouts.

Logo

If you want to display only one of the 3 layouts, you can use the following function, but we recommend that you customize all 3 layouts so that the ad displays correctly and brings the most value:

  com.ikame.android.sdk.widgets.IkmWALF#setIkmWALFType(IkmWALFType)
  

Sample Usage

layout_native_full_screen

Preloading an Ad

The preloadNativeAd() function in the IKSdkController class is used to preload a native ad and store it in the SDK system, allowing you to prepare an ad in advance so that it can be displayed more quickly when needed. This method optimizes ad delivery by ensuring that the ad is loaded and ready before it is shown to the user.

Reference

  com.ikame.android.sdk.IKSdkController#preloadNativeAd
  

Function Definition

  fun preloadNativeAd(
    screen: String,
    callback: IKLoadAdListener?
)
  

Parameters:

  • screenAd: considered as a unitId, our team will send you the screenAd list.
  • callback: IKLoadAdListener Interface - Provides methods for general ad loading processes, encompassing notifications for both successful loads and failures.

Sample Usage

Recall load current ad

Once you have successfully loaded the Ad before, if you want to reload the ad in that position. The loadAd function should not be called again. Use the recallLoadAd function

Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#reCallLoadAd
  

Function Definition

  fun reCallLoadAd(listener: IKShowWidgetAdListener?)
  

Parameters:

Sample Usage

Mix icon and media view

From SDK version 3.00.490 or higher

In some cases, when you customize NativeAd to a small form, it can only display icons. But some ad networks do not return icons. Therefore, the UI/UX will be quite ugly. Below I will introduce a way to help solve that problem by replacing the icon with displaying mediaView.

Note: in mediaViewVideo you need to set the minimum width and height to 120dp according to policy.

XMl layout sample layout_native_banner.xml

Destroy Ad

In certain scenarios, IkmWidgetAdView can be prone to memory leaks. Therefore, it is essential to destroy the ad when your Fragment or Activity is destroyed to manage resources properly.

Reference

  com.ikame.android.sdk.widgets.IkmWidgetAdView#destroyAd()
  

Function Definition

  fun destroyAd()
  

Sample usage

Classes and Interfaces

  • IKNativeTemplate Enum: Defines templates for native advertising, specifying layout and style configurations to be used within the application.
  • IKShowWidgetAdListener Interface: Manages callbacks for displaying widget ads, focusing on events for ad load success and failures.
  • IKLoadDisplayAdViewListener Interface: Handles callbacks related to the loading of display ad views, with attention to the completion of ad loads and error handling.
  • IKLoadAdListener Interface: Provides methods for general ad loading processes, encompassing notifications for both successful loads and failures.