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.
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
val adsView: IkmWidgetAdView? = findViewById(R.id.adsView)
adsView.attackLifecycle(this.lifecycle)
adsView.loadAd(
"home_native", IKNativeTemplate.NORMAL_LAYOUT,
object : IKShowWidgetAdListener {
override fun onAdShowed() {}
override fun onAdShowFail(error: IKAdError) {
adsView?.visibility = View.GONE
}
}
)
IkmWidgetAdView adsView = findViewById(R.id.adsView);
adsView.attachLifecycle(getLifecycle());
adsView.loadAd("native_screen_id", IKNativeTemplate.NORMAL_LAYOUT, new IKShowWidgetAdListener() {
@Override
public void onAdShowed() {
}
@Override
public void onAdShowFail(@NonNull IKAdError ikAdError) {
}
@Override
public void onAdClick() {
}
});
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
var displayWidgetAdView: IkmDisplayWidgetAdView? = null
IKSdkController.loadNativeDisplayAd("home_native", object : IKLoadDisplayAdViewListener {
override fun onAdLoaded(adObject: IkmDisplayWidgetAdView?) {
// Ad loaded with view object
displayWidgetAdView = adObject
}
override fun onAdLoadFail(error: IKAdError) {
// Handle ad load failure with view object
}
})
IkmDisplayWidgetAdView displayWidgetAdView;
IKSdkController.loadNativeDisplayAd("native_screen_id", new IKLoadDisplayAdViewListener() {
@Override
public void onAdLoaded(@Nullable IkmDisplayWidgetAdView adObject) {
displayWidgetAdView = adObject
}
@Override
public void onAdLoadFail(@NonNull IKAdError ikAdError) {
}
});
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
adsView?.showWithDisplayAdView(
"native_screen_id",
IKNativeTemplate.NORMAL_LAYOUT,
displayWidgetAdView,
object : IKShowWidgetAdListener {
override fun onAdShowed() {
}
override fun onAdShowFail(error: IKAdError) {
adsView?.visibility = View.GONE // Corrected from View.VISIBLE to View.GONE for error case
}
}
)
adsView.showWithDisplayAdView("native_screen_id", IKNativeTemplate.NORMAL_LAYOUT, displayWidgetAdView, new IKShowWidgetAdListener() {
@Override
public void onAdShowFail(@NonNull IKAdError ikAdError) {
}
@Override
public void onAdShowed() {
}
@Override
public void onAdClick() {
}
});
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.
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.
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
var displayWidgetAdView: IkmDisplayWidgetAdView? = null
IKSdkController.loadNativeDisplayAd("home_native", object : IKLoadDisplayAdViewListener {
override fun onAdLoaded(adObject: IkmDisplayWidgetAdView?) {
// Ad loaded with view object
displayWidgetAdView = adObject
}
override fun onAdLoadFail(error: IKAdError) {
// Handle ad load failure with view object
}
})
IkmDisplayWidgetAdView displayWidgetAdView;
IKSdkController.loadNativeDisplayAd("native_screen_id", new IKLoadDisplayAdViewListener() {
@Override
public void onAdLoaded(@Nullable IkmDisplayWidgetAdView adObject) {
displayWidgetAdView = adObject
}
@Override
public void onAdLoadFail(@NonNull IKAdError ikAdError) {
}
});
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
val adsView: IkmWidgetAdView? = findViewById(R.id.adsView)
adsView.attackLifecycle(this.lifecycle)
val adLayout = LayoutInflater.from(applicationContext).inflate(R.layout.layout_custom_admob, null, false) as IkmWidgetAdLayout
adLayout.titleView = findViewById(R.id.custom_headline)
adLayout.bodyView = findViewById(R.id.custom_body)
adLayout.callToActionView = findViewById(R.id.custom_call_to_action)
adLayout.iconView = findViewById(R.id.custom_app_icon)
adLayout.mediaView = findViewById(R.id.custom_media)
adsView.showWithDisplayAdView(
R.layout.shimmer_loading_native,
adLayout,
"home_native",
IKNativeTemplate.NORMAL_LAYOUT,
adObject,
object : IKShowWidgetAdListener {
override fun onAdShowed() {
}
override fun onAdShowFail(error: IKAdError) {
adsView?.visibility = View.GONE // Corrected from View.VISIBLE to View.GONE for error case
}
}
)
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
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.
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:
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.
warning
You should not call too many preloadNativeAd simultaneously to avoid affecting the ability to load ads and app performance. Let calculate the appropriate time to call preloadNativeAd
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
IKSdkController.preloadNativeAd("native_screen_id", object : IKLoadAdListener {
override fun onAdLoaded() {
// Ad loaded successfully
}
override fun onAdLoadFail(error: IKAdError) {
// Handle ad load failure
}
})
IKSdkController.preloadNativeAd("native_screen_id", new IKLoadAdListener() {
@Override
public void onAdLoaded() {
}
@Override
public void onAdLoadFail(@NonNull IKAdError ikAdError) {
}
});
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
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.
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.
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.