NativeAd
package com.intowow.sdk
public class NativeAd extends Ad

Characteristics
Support image and video.
Video is mute by default, and can be toggled by clicking it.
Creative, title and description of ad are accessible to app for customized layout.
Recommended Ad Placement
Custom
Request an ad
You could request an ad by:
private final static String PLACEMENT_NAME = "Obtain from your Intowow account manager";
private final static long LOAD_AD_TIMEOUT = 30000L;
private NativeAd mNativeAd = new NativeAd(mActivity);
private MediaView mMediaView = null;
RequestInfo requestInfo = new RequestInfo();
requestInfo.setPlacement(PLACEMENT_NAME);
requestInfo.setTimeout(LOAD_AD_TIMEOUT);
mNativeAd.setAdListener(new CEAdListener() {
@Override
public void onAdClicked(Ad ad) {
}
@Override
public void onAdImpression(Ad ad) {
}
@Override
public void onAdMute(Ad ad) {
}
@Override
public void onAdUnmute(Ad ad) {
}
@Override
public void onVideoStart(Ad ad) {
}
@Override
public void onVideoProgress(Ad ad, int totoalDuration, int currentPosition) {
}
@Override
public void onVideoEnd(Ad ad) {
}
});
mNativeAd.loadAdAsync(requestInfo, new CEAdRequestListener() {
@Override
public void onError(Ad ad, AdError error) {
}
@Override
public void onAdLoaded(Ad ad) {
if(mNativeAd != ad) {
return;
}
// Get ad title string.
String title = mNativeAd.getAdTitle()
// Get ad description string.
String adBody = mNativeAd.getAdBody();
// Get call to action string.
String callToAction = mNativeAd.getAdCallToAction();
// Instantiate MediaView
// please make sure to pass activity on to the mediaview
//
int width = your_defined_width;
mMediaView = new MediaView(activity);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
width, RelativeLayout.LayoutParams.WRAP_CONTENT);
mMediaView.setLayoutParams(params);
mMediaView.setNativeAd(mNativeAd);
// Add these materials to the UI hierarchy
}
});
remember to release ad if it is no longer to use.
@Override
protected void onDestroy() {
if(mMediaView != null) {
mMediaView.destroy();
mMediaView = null;
}
if(mNativeAd != null) {
mNativeAd.destroy();
mNativeAd = null;
}
...
...
super.onDestroy();
}
Advance Integration
After ad loading, you can configure your ad by using
AdProperty
with MediaView class.You could use hasVideoContent() to check if the ad is video or not after ad loaded.
NOTE
Please make sure to new an instance before requesting the ad. Do not keep the returned ad too long, otherwise you may display the out-of-dated ad.
Public constructors
NativeAd(Context context) Instantiates a new native ad.
Public methods
void
destroy() Release the native ad.
void
downloadAndDisplayImage(NativeAd.Image image, ImageView imageView) Download and set image to imageView.
String
getAdBody() Get the ad description. you can call this method after onAdLoaded() of AdListener.
String
getAdCallToAction() Get the ad call to action text. you can call this method after onAdLoaded() of AdListener.
Image
getAdIcon() Get the ad icon. you can call this method after onAdLoaded() of AdListener.
String
getAdTitle() Get the ad title. You can call this method after onAdLoaded() of AdListener.
loadAdInstant(RequestInfo requestInfo) Load ad with requestInfo (synchronous)
void
loadAdAsync(RequestInfo requestInfo, CEAdRequestListener listener)
Load ad with requestInfo (asynchronous)
void
registerViewForInteraction(View v) Register view for interaction.
void
registerViewForInteraction(View v, List clickableViews) Register view for interaction.
void
setAdListener(CEAdListener listener) Set the ad listener.
void
setOnTouchListener(OnTouchListener listener) Set onTouchListener.
void
unregisterView() Unregister view.
Inherited methods
int
getAdId() Get the ad id.
String
getCampaignId() Get the campaign id.
String
getEngageUrl() Get the engage url.
int
getPlace() Get the ad place.
String
getPlacement() Get the ad placement.
Rect
getSize() Get the ad size. It should be called after onAdLoaded().
String
getToken() Get the ad token for tracking.
long
getTotalFileSize() Get the ad file size on device.
String
getVideoCoverPath() Get video cover file path. It should be called after onAdLoaded().
boolean
hasVideoContent() Check if the ad has video content or not.
boolean
isValid() Check if the ad is still valid for serving.
void
setSize(Rect rect) Set the ad size.
Public constructors
NativeAd
NativeAd(Context context, String placement)
Instantiates a new native ad.
Parameters
context
Context: the context.
Public methods
destroy
void destroy()
Release the ad.
downloadAndDisplayImage
void downloadAndDisplayImage()
Download and display image. you can call this method after onAdLoaded() of AdListener.
getAdBody
String getAdBody()
Get the ad description. you can call this method after onAdLoaded() of AdListener.
Returns
String
the ad description.
getAdCallToAction
String getAdCallToAction()
Get the ad call to action text. you can call this method after onAdLoaded() of AdListener.
Returns
String
the ad call to action text.
getAdIcon
Image getAdIcon()
Get the ad icon. you can call this method after onAdLoaded() of AdListener.
Returns
Image
the ad icon. you can get icon url to download the icon file by calling image.getUrl()
, and get icon size by calling image.getWidth()
and image.getHeight()
getAdTitle
String getAdTitle()
Get the ad title. you can call this method after onAdLoaded() of AdListener.
Returns
String
the ad title.
loadAdInstant
CERequestResult loadAdInstant(RequestInfo requestInfo)
Load ad with RequestInfo (synchronous)
Parameters
requestInfo
RequestInfo: the request info such as placement and timeout.
loadAdAsync
void loadAdAsync(RequestInfo requestInfo, CEAdRequestListener listener)
Load ad with RequestInfo (asynchronous)
Parameters
requestInfo
RequestInfo: the request info such as placement and timeout.
listener
CEAdRequestListener: know the result of loadAdAsync
registerViewForInteraction(View v)
void registerViewForInteraction(View v)
Register view for interaction.
Parameters
v
View: the view for interaction.
registerViewForInteraction(View v, List clickableViews)
void registerViewForInteraction(View v, List clickableViews)
Register view for interaction.
Parameters
v
View: the view for interaction.
clickableViews
List: views for interaction.
setAdListener
void setAdListener(CEAdListener listener)
Set the ad listener.
Parameters
listener
CEAdListener: the ad listener.
setOnTouchListener
void setOnTouchListener(OnTouchListener listener)
Set onTouchListener.
Parameters
listener
OnTouchListener: the onTouchListener.
unregisterView
void unregisterView()
Unregister view.
Last updated