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

Leaderboard 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 HyBidLeaderboardAdView inside your layout file

<net.pubnative.lite.sdk.views.HyBidLeaderboardAdView
    android:id="@+id/hybid_leaderboard"
    android:layout_width="728dp"
    android:layout_height="90dp"
    android:layout_gravity="center_horizontal"/>

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

private HyBidLeaderboardAdView mLeaderboard;

Get a reference to it from your code.

mLeaderboard = findViewById(R.id.hybid_leaderboard);

Requesting and displaying the ad

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

private void loadLeaderboard() {
    mLeaderboard.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 HyBidLeaderboardAdView 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 leaderboard when the activity or fragment are destroyed

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

<- Rectangle Banners            -> Interstitials