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.
The Banner ad unit is designed as a common view to be injected in any place in your app. Banner ad unit size is 320x50 and it supports Display (Static and Rich Media) ad format.
After finishing all the steps for receiving a Banner ad just get BannerPlacement from Controller and retrieve View with Banner inside.
BannerPlacement bannerPlacement = null;
try {
bannerPlacement = ((BannerPlacement) Controller.getInstance().getPlacement(placementId));
} catch (DioSdkException e) {
e.printStackTrace();
}
if (bannerPlacement != null) {
View bannerView = bannerPlacement.getBanner(getApplicationContext(), requestId);
}
Now you can add this view to any part of your app. We recommend creating a special container view in your layout reserved for Banner.
if (bannerView != null) {
viewReservedForAd.addView(bannerView);
}
Note: Default size for Banner is 320x50 pixels and it will be scaled to dp according to device resolution and pixel density.
On this subject, best practices dictate to close the Banner Ad after activity has been destroyed as well as signal to the Ad that the activity has been paused or resumed.
@Override
public void onDestroy() {
try {
Controller.getInstance()
.getPlacement(<placementId>)
.getAdRequestById(<requestId>)
.getAdProvider().getAd.close();
} catch (DioSdkException e) {
// error handling
}
}
@Override
public void onPause() {
super.onPause();
try {
Controller.getInstance()
.getPlacement(<placementId>)
.getAdRequestById(<requestId>)
.getAdProvider().getAd().activityPaused();
} catch (Exception e) {
// error handling
}
}
@Override
public void onResume() {
super.onResume();
try {
Controller.getInstance()
.getPlacement(<placementId>)
.getAdRequestById(<requestId>)
.getAdProvider().getAd().activityResumed();
} catch (Exception e) {
// error handling
}
}
Comments
0 comments
Please sign in to leave a comment.