Before You Start Make Sure:
- App and Placement set up on Publisher Portal
- SDK is installed
- SDK is initialized
- Each Ad request has "Testing" status which enables it to test integrations.
Infeed ads fit inside a feed in your app - the integration requires injecting a view into your feed adapter.
Infeed ad unit supports both Video and Display (Static and Rich Media) ad formats. Display ad size is 300x250.
Infeed ads are designed to be integrated into recycler views. A best practice is to extend your RecyclerView.Adapter and RecyclerView.ViewHolder (AdHolder in example), to pass them the relevant Placement and AdRequest IDs .
Inside the adapter’s onCreateViewHolder use InfeedAdContainer.getAdView(Context context) method to get the ad view and return it in a ViewHolder.
Inside the adapter’s onBindViewHolder you will need to retrieve a InfeedAdContainer object from the Placement object by calling it’s getInfeedContainer method and passing it the ApplicationContext and the AdRequest id as parameters. Then use the InfeedAdContainer.bindTo method to bind the Ad to the ViewHolder's itemView.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
context = parent.getContext().getApplicationContext();
RelativeLayout adView = InfeedAdContainer.getAdView(context);
Return new AdHolder(adView);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
{
try {
InfeedPlacement placement = (InfeedPlacement)
Controller.getInstance().getPlacement(<placementId>);
placement.setFullWidth(false);
InfeedAdContainer infeedAdContainer =
placement.getInfeedContainer(context, <requestId>);
infeedAdContainer.bindTo((RelativeLayout) ((AdHolder)
holder).itemView);
} catch (DioSdkException e) {
// error handling
}
}
In order to control if an Infeed is displayed with full-width (i.e. without margins):
placement.setFullWidth(false/true); // false by default
In order to control if an Infeed (video only) is displayed without top and bottom frames:
placement.setFrameless(false/true); // false by default
In order to control if an Infeed video is displaying countdown timer:
placement.setShowTimer(false/true); // true by default
- Call ad.close() to stop the ad and release the resources associated with it.
- Call ad.leave() to pause the video ad.
- Call ad.reenter() to resume the video ad.
try {
Controller.getInstance()
.getPlacement(<placementId>)
.getAdRequestById(<requestId>)
.getAdProvider().getAd().close();
} catch (DioSdkException e) {
// error handling
}
Comments
0 comments
Please sign in to leave a comment.