HyBid Rectangle Banners - pubnative/pubnative-hybid-android-sdk GitHub Wiki

Rectangle Banners will be rendered using the HyBid SDK.

Requirements:

  • Ad Zone Id from the PubNative Publisher Dashboard

Code sample

You can find a demo app with code samples for this type of integration here.

Create XML layout

Create a HyBidMRectAdView inside your layout file

<net.pubnative.lite.sdk.views.HyBidMRectAdView
    android:id="@+id/hybid_mrect"
    android:layout_width="300dp"
    android:layout_height="250dp"
    android:layout_gravity="center_horizontal"/>

Create an attribute to hold the reference to the UI element.

private HyBidMRectAdView mMRect;

Get a reference to it from your code.

mMRect = findViewById(R.id.hybid_mrect);

Requesting and displaying the ad

Use the load method to request an ad using the zone id and setting a listener for the mrect.

private void loadMRect() {
    mMRect.load("ZONE_ID", new PNAdView.Listener() {
        @Override
        public void onAdLoaded() {
                
        }

        @Override
        public void onAdLoadFailed(Throwable error) {

        }

        @Override
        public void onAdImpression() {

        }

        @Override
        public void onAdClick() {

        }
    });
}

Once the ad is loaded successfully from the server, the HyBidMRectAdView will render it and notify when it's ready via the onAdLoaded callback. Any error during fetch or rendering will be received via the onAdLoadFailed callback.

onAdImpression and onAdClick just notify of clicks and impressions. No code needs to be added there. Use those callbacks in case you want to hide the ad after click or some similar use case.

Finally destroy the mrect when the activity or fragment are destroyed

@Override
public void onDestroy() {
    if (mMRect != null) {
        mMRect.destroy();
    }
    super.onDestroy();
}

<- Banners            -> Leaderboard Banners