Skip to main content
Version: 5.x.x

Banner Ads

Overview

Before You Start. Make sure that you have correctly integrated the BlueStack SDK into your application. Integration is outlined here.

Create a BannerView

To create a banner you have to init an object with type BannerView.

// Create a new bannerView.
BannerView bannerView = new BannerView(getActivity());
bannerView.setPlacementId("Placement_ID")
bannerView.setAdSize(AdSize.BANNER)

// Add new bannerView into adLayout.
adLayout.removeAllViews();
adLayout.addView(bannerView);

Note: if your application support different screen sizes on Tablet and Phone, it is better to use following AdSize:

AdSize  adSize = getResources().getBoolean(R.bool.is_tablet) ? AdSize.DYNAMIC_LEADERBOARD : AdSize.DYNAMIC_BANNER;
bannerView.setAdSize(adSize)

Load a Banner Ad

Note: Make all calls to the BlueStack SDK on the main thread.

With RequestOptions

To request an Banner ad using RequestOptions, provide an instance of RequestOptions in the BannerView's load method:

bannerView.load(requestOptions)

Without RequestOptions

bannerView.load()

Ad events

Register for banner events

To recieve ad's lifecycle events regisger a listerner in BannerView.

public class BannerAdFragment extends Fragment implements BannerViewListener {
...
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
bannerView = new BannerView(requireActivity());
bannerView.setBannerViewListener(this);
..
}
...
}

Implement banner events

The SDK will notify your Listener of all possible events listed below :

  • onAdLoad(): will be called by the SDK when banner ad finishes loading.
@Override
public void onAdLoad(int preferredHeightDP){
Log.d(TAG, "your banner is ready");
...
// it's preferable to adjust the ad container view size to match the returned Ad size for a better display
...

}
  • onAdFailToLoad(): will be called when all ads servers fail. it will return the error of last called ads server.
@Override
public void onAdFailToLoad(Exception exception) {
Log.e(TAG, "banner did fail :" + exception);
}
  • onResize() : will be called when the banner has changed size
@Override
public void onResize(Size size) {
...
// it's preferable to adjust the ad container view size to match the returned Ad size for a better display
Log.d(TAG, "Banner did resize w dp " + size.getWidth() + " h dp " + size.getHeight());
...
}
  • onAdRefresh() : will be called when the banner has refreshed
@Override
public void onAdRefresh() {
Log.d(TAG, "banner refresh succeed")
}
  • onAdFailToRefresh() : will be called when the banner fail to refresh.
@Override
public void onAdFailToRefresh(Exception exception) {
Log.e(TAG, "banner did fail to refresh :" + exception);
}
  • onAdClicked(): will be called when user click the banner ad.
@Override
public void onAdClicked() {
Log.d(TAG, "Ad Clicked");
}

Destroying Banner Ad

When you have finished your ads plant you must free the memory.

@Override
protected void onDestroy() {
bannerView.destroy();
bannerView = null;
super.onDestroy();
}

AdSize

BlueStack ads provides variant pre-defined sizes, See table below for details about our supported standard banner sizes:

MNGAdSizeDescriptionDimensions in dp (WxH)
BANNERStandard Banner320 x 50
LARGE_BANNERLarge Banner320 x 100
MEDIUM_RECTANGLEMedium Rectangular Banner300 x 250
DYNAMIC_BANNERAdjusted BannerScreen width x 50
FULL_BANNERFull Banner468 x 60
LEADERBOARDStandard Banner for tablet728 x 90
DYNAMIC_LEADERBOARDAdjusted Banner for tabletScreen width x 90

Adapt the banner size after loading

You can resize the Banner View height to match the creative's width/height ratio, this is often the case when your Banner View needs to deliver view over 50 dp. (This does not happen when setting your view as wrap_content)

Here's an example:

XML Code :

<LinearLayout
android:id="@+id/bannerContainer"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"/>
@Override
public void onResize(Size size) {
// convert Dp To Pixel
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float bannerPreferredHeightPx = size.getHeight() * (metrics.densityDpi / 160f);

// adapt the banner size
bannerContainer.getLayoutParams().height = bannerPreferredHeightPx;
bannerContainer.requestLayout();
}

OR

@Override
public void onAdLoad(int preferredHeightDP) {
// convert Dp To Pixel
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float bannerPreferredHeightPx = preferredHeightDP * (metrics.densityDpi / 160f);

// adapt the banner size
bannerContainer.getLayoutParams().height = bannerPreferredHeightPx;
bannerContainer.requestLayout();
}

Example

ExampleDescription
banner50-mngads-android-min.png Banner - (50dp or 90dp )A banner is a small bar ad that appears at the bottom or top of your content. Usually sized 320 x 50. Only include one ad per page or show one ad at a time if scrolling. In all cases, the banner width is flexible with a minimum of 320px.. If you are building your app for iPad consider using 90px and 50px for iphone.
banner250-mngads-android-min.png Square - Medium rectangle (300 x 250)Square banner also known as a medium rectangle (300 x 250). This format can increase earnings when both text and image ads are enabled. Performs well when embedded within text content or at the end of articles.