Before You Start Make Sure:
- App and Placement set up on Publisher Portal
- SDK is installed
- SDK is initialized
- In order to test integration there are test Ads, under the Placement name "Testing".
Medium Rectangle ad unit is designed as a common view to be injected within a variety of placements in-app. Medium Rectangle supports Display (Static and Rich Media) ad format. Medium Rectangle ad unit size is 300x250.
After finishing all the steps for receiving ad, get MediumRectanglePlacement from Controller and retrieve View with MediumRectangle inside.
MediumRectanglePlacement mediumRectanglePlacement = null;
try {
mediumRectanglePlacement = ((MediumRectanglePlacement) Controller
.getInstance().getPlacement(placementId));
} catch (DioSdkException e) {
e.printStackTrace();
}
if (mediumRectanglePlacement != null) {
View mediumRectangleView = mediumRectanglePlacement
.getMediumRectangle(getApplicationContext(), requestId);
}
Now you can add this view to any part of your app. We recommend to create a special container view in your layout reserved for Medium Rectangle.
if (mediumRectangleView != null) {
viewReservedForAd.addView(mediumRectangleView);
}
Note: Default size for Medium Rectangle is 350x250 pixels and it will be scaled to DP according to device resolution and pixel density.
On this subject, best practices dictate to close the Medium Rectangle 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.