Self-developed aggregation

SDK Initialization

There are two ways to call the initialization interface. You can use either fast initialization or dynamic initialization to access.

Fast initialization

  1. Configure the App Id of the BeesAds platform in app/src/main.AndroidManifest.xml.

<manifest>
  <application>
    <meta-data
        android:name="com.bees.ads.sdk.APP_ID"
        android:value="application id" />
  </application>
</manifest>
  1. Call the initialization interface

BeesSdk.getInstance(context).initialize(new OnSdkInitializationListener());

The parameters are described as follows:

Parameter name

Parameter Description

context

Context

listener

Initialize the listener

Code example:

BeesSdk.getInstance(context).initialize(new OnSdkInitializationListener() {
    @Override public void onInitializeSuccess() {
        // Initialization successful
    }

    @Override public void onInitializeFailed(@NonNull AdsError error) {
        // Initialization failed
    }
});

Dynamic Initialization

Call the following initialization interface:

BeesSdk getInstance(Context context, String appId).initialize(OnSdkInitializationListener listener)

The parameters are described as follows:

Parameter name

Parameter Description

context

Context

appId

BeesAds background application id

listener

Initialize the listener

Code example:

BeesSdk.getInstance(this, "Your App Id").initialize(new OnSdkInitializationListener() {
    @Override public void onInitializeSuccess() {
        // Initialization successful
    }

    @Override public void onInitializeFailed(@NonNull AdsError sdkError) {
        // Initialization failed
    }
});

OnSdkInitializationListener Description:

Initialization callback interface

Method Name

Method Description

onInitializeSuccess()

SDK initialization successful

onInitializeFailed(@NonNull AdsError adsError)

SDK initialization failed

SDK interface introduction

  1. load

BeesBannerAd bannerAdView = new BeesBannerAd(context);
bannerAdView.setListener(new BeesBannerAdListener());
bannerAdView.setAdSize(BannerSize.BANNER);
bannerAdView.setAdUnitId("«ad-unit-id»");
bannerAdView.loadAd();
  1. size

type

illustrate

BannerSize.BANNER

Standard banner, size: 320x50

BannerSize.LARGE_BANNER

Large banner, size: 320x100

BannerSize.MEDIUM_RECTANGLE

Medium rectangle ad, size: 300x250

BannerSize.FULL_BANNER

Full width banner, suitable for tablet devices, size: 468x60

BannerSize.LEADERBOARD

Extra wide banner, suitable for tablet devices, size: 728x90

  1. exhibit

ViewGroup rootView = findViewById(android.R.id.content)
rootView.addView(bannerAdView)
  1. Callbacks

bannerAdView.setListener(new BeesBannerAdListener() {
    @Override public void onAdLoaded() {
        // Ad loaded successfully
    }

    @Override public void onAdLoadFailed(@NonNull AdsError adsError) {
        // Ad loading failed
    }

    @Override public void onAdDisplayed() {
        // Advertisement display success
    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {
        // Ad display failed
    }

    @Override public void onAdImpression() {
        // Ad exposure callback
    }

    @Override public void onAdClicked() {
        // Ad clicked
    }

    @Override public void onAdHidden() {
        // Ads are hidden
    }
});
  1. destroy

public class ExampleActivity extends Activity {
    
    @Override protected void onDestroy() {
        if (bannerAdView != null) {
            bannerAdView.destroy();
            bannerAdView = null;
        }
        super.onDestroy();
    }
}
  1. Example

public class ExampleActivity extends Activity implements BeesAdListener {

    @Nullable
    private BeesBannerAd mBannerAd;

    private void createBannerAd() {
        mBannerAd = new BeesBannerAd(this);
        mBannerAd.setAdSize(BannerSize.BANNER);
        mBannerAd.setAdUnitId("«ad-unit-id»");
        mBannerAd.setListener(this);
        mBannerAd.loadAd();
    }

    @Override protected void onPause() {
        if (mBannerAd != null) {
            mBannerAd.pause();
        }
        super.onPause();
    }

    @Override protected void onResume() {
        super.onResume();
        if (mBannerAd != null) {
            mBannerAd.resume();
        }
    }

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

    @Override public void onAdLoaded() {

    }

    @Override public void onAdLoadFailed(@NonNull AdsError adsError) {

    }

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {

    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {

    }
}

Native Advertising

  1. load

BeesNativeAdLoader.load(this, "«ad-unit-id»", new NativeAdLoadCallback() {
    @Override public void onAdLoaded(@NonNull BeesNativeAd beesNativeAd) {
      // Ad loaded successfully
    }

    @Override 
    public void onAdLoadFailed(@NonNull AdsError error) {
       // Ad loading failed
    }
});
  1. monitor

if (nativeAdLoader != null && nativeAdLoader.isReady()) {
    nativeAdLoader.setAdListener(new BeesNativeAdListener());
}

BeesNativeAdListener Description

Native ad listener

Method Name

Method Description

onAdDisplayFailed(@NonNull AdsError adsError)

Ad display failed

onAdImpression()

Ad exposure callback

onAdClicked()

Ad click callback

  1. exhibit

    1. Create a native ad view hierarchy

      <?xml version="1.0" encoding="utf-8"?>
      <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="https://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
      
        <ImageView
          android:id="@+id/native_id_icon"
        … />
        <TextView
          android:id="@+id/native_id_title"
        … />
        <RatingBar
          android:id="@+id/native_id_star"
        … />
        <TextView
          android:id="@+id/native_id_advertiser"
        … />
        <TextView
          android:id="@+id/native_id_body"
        … />
        <FrameLayout
          android:id="@+id/native_layout_media"
        … />
        <Button
          android:id="@+id/native_id_cta"
        … />
      </androidx.constraintlayout.widget.ConstraintLayout>
    2. Display ads and bind native ad controls

      if (nativeAdLoader != null && nativeAdLoader.isReady()) {
          nativeAdLoader.showAd(adContainerViewGroup, new BeesNativeViewBinder(nativeAdView));    
      }       
  2. destroy

if (mNativeAdLoader != null) {
    mNativeAdLoader.destroy();
    mNativeAdLoader = null;
}
  1. Example

public class ExampleActivity extends Activity implements BeesNativeAdListener {

    @Nullable
    private BeesNativeAdLoader mNativeAdLoader;

    private int mRetryAttemptCount = 0;

    private void loadNativeAd() {
        mNativeAdLoader = BeesNativeAdLoader.load(this, "«ad-unit-id»", new NativeAdLoadCallback() {
            @Override public void onAdLoaded(@NonNull BeesNativeAd beesNativeAd) {
                mRetryAttemptCount = 0;

                showNativeAd(beesNativeAd);
            }

            @Override public void onAdLoadFailed(@NonNull AdsError error) {
                mRetryAttemptCount++;

                long delayMillis = TimeUnit.SECONDS.toMillis((long) Math.pow(2, Math.min(6, mRetryAttemptCount)));

                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        loadNativeAd();
                    }
                }, delayMillis);
            }
        });
    }

    private void showNativeAd(@NonNull BeesNativeAd beesNativeAd) {
        if (mNativeAdLoader != null && mNativeAdLoader.isReady()) {
            mNativeAdLoader.setAdListener(this);
            mNativeAdLoader.show(findViewById(R.id.ad_container), new BeesNativeViewBinder(R.layout.layout_debugger_native) {

                @Override public void renderAdView(@NonNull ViewGroup adLayout) {

                    // icon
                    NativeAdImage iconNativeImage = beesNativeAd.getIconImage();
                    if (iconNativeImage != null) {
                        ImageView iconView = adLayout.findViewById(R.id.native_id_icon);
                        if (iconNativeImage.getDrawable() != null) {
                            iconView.setImageDrawable(iconNativeImage.getDrawable());
                            iconView.setVisibility(View.VISIBLE);
                            // set icon view
                            setIconView(iconView);
                        } else {
                            iconView.setVisibility(View.GONE);
                        }
                    }

                    // title
                    TextView titleView = adLayout.findViewById(R.id.native_id_title);
                    if (TextUtils.isEmpty(beesNativeAd.getTitle())) {
                        titleView.setVisibility(View.GONE);
                    } else {
                        titleView.setText(beesNativeAd.getTitle());
                        titleView.setVisibility(View.VISIBLE);
                        // set title view
                        setTitleView(titleView);
                    }

                    // advertiser
                    TextView advertiserView = adLayout.findViewById(R.id.native_id_advertiser);
                    if (TextUtils.isEmpty(beesNativeAd.getAdvertiser())) {
                        advertiserView.setVisibility(View.GONE);
                    } else {
                        advertiserView.setText(beesNativeAd.getAdvertiser());
                        advertiserView.setVisibility(View.VISIBLE);
                        // set advertiser view
                        setAdvertiserView(advertiserView);
                    }

                    // body
                    TextView bodyView = adLayout.findViewById(R.id.native_id_body);
                    if (TextUtils.isEmpty(beesNativeAd.getBody())) {
                        bodyView.setVisibility(View.GONE);
                    } else {
                        bodyView.setText(beesNativeAd.getBody());
                        bodyView.setVisibility(View.VISIBLE);
                        // set body view
                        setBodyView(bodyView);
                    }

                    // starRating
                    RatingBar ratingBar = adLayout.findViewById(R.id.native_id_star);
                    if (beesNativeAd.getStarRating() == null) {
                        ratingBar.setVisibility(View.GONE);
                    } else {
                        ratingBar.setRating(beesNativeAd.getStarRating().floatValue());
                        ratingBar.setVisibility(View.VISIBLE);
                        // set star rating view
                        setStarRatingView(ratingBar);
                    }

                    // callToAction
                    TextView callToActionView = adLayout.findViewById(R.id.native_id_cta);
                    if (TextUtils.isEmpty(beesNativeAd.getCallToAction())) {
                        callToActionView.setVisibility(View.GONE);
                    } else {
                        callToActionView.setText(beesNativeAd.getCallToAction());
                        callToActionView.setVisibility(View.VISIBLE);
                        // set call to action view
                        setCallToActionView(callToActionView);
                    }

                    // media view
                    FrameLayout mediaLayout = adLayout.findViewById(R.id.native_layout_media);
                    View mediaView = beesNativeAd.getMediaView();
                    if (mediaView != null) {
                        mediaLayout.removeAllViews();
                        if (mediaView.getParent() != null) {
                            ((ViewGroup) mediaView.getParent()).removeView(mediaView);
                        }
                        FrameLayout.LayoutParams mainImageParam = new FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
                        mainImageParam.gravity = Gravity.CENTER;
                        mediaView.setLayoutParams(mainImageParam);
                        mediaLayout.addView(mediaView, mainImageParam);
                        mediaLayout.setVisibility(View.VISIBLE);
                        // set media view
                        setMediaLayoutView(mediaLayout);
                    } else {
                        mediaLayout.setVisibility(View.GONE);
                    }
                }
            });
        }
    }

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

    @Override public void onAdImpression() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {
        loadNativeAd();
    }

    @Override public void onAdClicked() {

    }
}

Splash screen ads

  1. load

BeesAppOpenAd.load(this, "«ad-unit-id»", new AppOpenAdLoadCallback() {
    @Override 
    public void onAdLoaded(@NonNull BeesAppOpenAd appOpenAd) {
        // Ad loaded successfully
    }

    @Override 
    public void onAdLoadFailed(@NonNull AdsError error) {
       // Ad loading failed
    }
});
  1. monitor

appOpenAd.setAdListener(new BeesAdsListener() {
    @Override public void onAdDisplayed() {
        
    }

    @Override public void onAdDisplayFailed(@NonNull AdsError error) {

    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {

    }
});

Callback description:

Method Name

Method Description

onAdDisplayed()

Advertisement display success

onAdDisplayFailed(@NonNull AdsError adsError)

Ad display failed

onAdImpression()

Ad exposure callback

onAdClicked()

Ad click callback

onAdHidden()

Ad hide callback

  1. exhibit

if (appOpenAd != null) {
    appOpenAd.show(activity);
}
  1. Example

public class AppOpenExampleActivity extends Activity implements BeesAdsListener {

    @Nullable
    private BeesAppOpenAd mAppOpenAd;

    private int mRetryAttemptCount;

    private void loadAppOpenAd() {
        BeesAppOpenAd.load(this, "«ad-unit-id»", new AppOpenAdLoadCallback() {
            @Override public void onAdLoaded(@NonNull BeesAppOpenAd appOpenAd) {
                mRetryAttemptCount = 0;
                mAppOpenAd = appOpenAd;
                showAppOpenAd();
            }

            @Override public void onAdLoadFailed(@NonNull AdsError error) {
                mAppOpenAd = null;
                mRetryAttemptCount++;

                long delayMillis = TimeUnit.SECONDS.toMillis((long) Math.pow(2, Math.min(6, mRetryAttemptCount)));

                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        loadAppOpenAd();
                    }
                }, delayMillis);
            }
        });
    }

    private void showAppOpenAd() {
        if (mAppOpenAd != null) {
            mAppOpenAd.setAdListener(this);
            mAppOpenAd.show(this);
        }
    }

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {
        mAppOpenAd = null;
        loadAppOpenAd();
    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {
        mAppOpenAd = null;
        loadAppOpenAd();
    }
}

Interstitial Ads

  1. load

BeesInterstitialAd.load(this, "«ad-unit-id»", new InterstitialAdLoadCallback() {
    @Override 
    public void onAdLoaded(@NonNull BeesInterstitialAd interstitialAd) {
        //Ad loaded successfully
    }

    @Override 
    public void onAdLoadFailed(@NonNull AdsError error) {
       // Ad loading failed
    }
});
  1. monitor

interstitialAd.setAdListener(new BeesAdsListener() {
    @Override public void onAdDisplayed() {
        // Ad loading successfully
    }

    @Override public void onAdDisplayFailed(@NonNull AdsError error) {
        // Ad loading failed
    }

    @Override public void onAdImpression() {
        // Ad exposure callback
    }

    @Override public void onAdClicked() {
        // Ad click callback
    }

    @Override public void onAdHidden() {
        // Ad hide callback
    }
});

Callback description:

Method Name

Method Description

onAdDisplayed()

Advertisement display success

onAdDisplayFailed(@NonNull AdsError adsError)

Ad display failed

onAdImpression()

Ad exposure callback

onAdClicked()

Ad click callback

onAdHidden()

Ad hide callback

  1. exhibit

if (interstitialAd != null) {
    interstitialAd.show(activity);
}
  1. Example

public class ExampleActivity extends Activity implements BeesAdsListener {

    @Nullable
    private BeesInterstitialAd mInterstitialAd;

    private int mRetryAttemptCount;

    private void loadInterstitialAd() {
        BeesInterstitialAd.load(this, "«ad-unit-id»", new InterstitialAdLoadCallback() {
            @Override public void onAdLoaded(@NonNull BeesInterstitialAd beesInterstitialAd) {
                mRetryAttemptCount = 0;
                mInterstitialAd = beesInterstitialAd;
                showInterstitialAd();
            }

            @Override public void onAdLoadFailed(@NonNull AdsError error) {
                mInterstitialAd = null;
                mRetryAttemptCount++;

                long delayMillis = TimeUnit.SECONDS.toMillis((long) Math.pow(2, Math.min(6, mRetryAttemptCount)));

                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        loadInterstitialAd();
                    }
                }, delayMillis);
            }
        });
    }

    private void showInterstitialAd() {
        if (mInterstitialAd != null) {
            mInterstitialAd.setAdListener(this);
            mInterstitialAd.show(this);
        }
    }

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {
        mInterstitialAd = null;
        loadInterstitialAd();
    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {
        mInterstitialAd = null;
        loadInterstitialAd();
    }
}

Rewarded ads

  1. load

BeesRewardedAd.load(this, "«ad-unit-id»", new RewardedAdLoadCallback() {
    @Override 
    public void onAdLoaded(@NonNull BeesRewardedAd rewardedAd) {
        // Ad loaded successfully
    }

    @Override 
    public void onAdLoadFailed(@NonNull AdsError error) {
       // Ad loading failed
    }
});
  1. monitor

rewardedAd.setAdListener(new BeesRewardedListener() {

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError error) {

    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdUserRewarded() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {

    }
});

Callback description:

Method Name

Method Description

onAdDisplayed()

Advertisement display success

onAdDisplayFailed(@NonNull AdsError adsError)

Ad display failed

onAdImpression()

Ad exposure callback

onAdUserRewarded()

Ad reward callback

onAdClicked()

Ad click callback

onAdHidden()

Ad hide callback

  1. exhibit

if (rewardedAd != null) {
    rewardedAd.show(activity);
}
  1. Example

public class ExampleActivity extends Activity implements BeesRewardedListener {

    @Nullable
    private BeesRewardedAd mRewardedAd;

    private int mRetryAttemptCount;

    private void loadRewardedAd() {
        BeesRewardedAd.load(this, "«ad-unit-id»", new RewardedAdLoadCallback() {
            @Override public void onAdLoaded(@NonNull BeesRewardedAd rewardedAd) {
                mRetryAttemptCount = 0;
                mRewardedAd = rewardedAd;
                showRewardedAd();
            }

            @Override public void onAdLoadFailed(@NonNull AdsError error) {
                mRewardedAd = null;
                mRetryAttemptCount++;

                long delayMillis = TimeUnit.SECONDS.toMillis((long) Math.pow(2, Math.min(6, mRetryAttemptCount)));

                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        showRewardedAd();
                    }
                }, delayMillis);
            }
        });
    }

    private void showRewardedAd() {
        if (mRewardedAd != null) {
            mRewardedAd.setAdListener(this);
            mRewardedAd.show(this);
        }
    }

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {
        mRewardedAd = null;
        loadRewardedAd();
    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {
        mRewardedAd = null;
        loadRewardedAd();
    }

    @Override public void onAdUserRewarded() {

    }
}

Rewarded interstitial ads

  1. load

BeesRewardedInterstitialAd.load(this, "«ad-unit-id»", new RewardedInterstitialAdLoadCallback() {
    @Override 
    public void onAdLoaded(@NonNull BeesRewardedInterstitialAd rewardedInterstitialAd) {
        // Ad loaded successfully
    }

    @Override 
    public void onAdLoadFailed(@NonNull AdsError error) {
       // Ad loading failed
    }
});
  1. monitor

rewardedInterstitialAd.setAdListener(new BeesRewardedListener() {

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError error) {

    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdUserRewarded() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {

    }
});

Callback description:

Method Name

Method Description

onAdDisplayed()

Ad display success

onAdDisplayFailed(@NonNull AdsError adsError)

Ad display failed

onAdImpression()

Ad exposure callback

onAdUserRewarded()

Ad reward callback

onAdClicked()

Ad click callback

onAdHidden()

Ad hide callback

  1. exhibit

if (rewardedInterstitialAd != null) {
    rewardedInterstitialAd.show(activity);
}
  1. Example

public class ExampleActivity extends Activity implements BeesRewardedListener {

    @Nullable
    private BeesRewardedInterstitialAd mRewardedInterstitialAd;

    private int mRetryAttemptCount;

    private void loadRewardedInterstitialAd() {
        BeesRewardedInterstitialAd.load(this, "«ad-unit-id»", new RewardedInterstitialAdLoadCallback() {
            @Override public void onAdLoaded(@NonNull BeesRewardedInterstitialAd rewardedInterstitialAd) {
                mRetryAttemptCount = 0;
                mRewardedInterstitialAd = rewardedInterstitialAd;
                showRewardedInterstitialAd();
            }

            @Override public void onAdLoadFailed(@NonNull AdsError error) {
                mRewardedInterstitialAd = null;
                mRetryAttemptCount++;

                long delayMillis = TimeUnit.SECONDS.toMillis((long) Math.pow(2, Math.min(6, mRetryAttemptCount)));

                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        loadRewardedInterstitialAd();
                    }
                }, delayMillis);
            }
        });
    }

    private void showRewardedInterstitialAd() {
        if (mRewardedInterstitialAd != null) {
            mRewardedInterstitialAd.setAdListener(this);
            mRewardedInterstitialAd.show(this);
        }
    }

    @Override public void onAdDisplayed() {

    }

    @Override public void onAdDisplayFailed(@NonNull AdsError adsError) {
        mRewardedInterstitialAd = null;
        loadRewardedInterstitialAd();
    }

    @Override public void onAdImpression() {

    }

    @Override public void onAdClicked() {

    }

    @Override public void onAdHidden() {
        mRewardedInterstitialAd = null;
        loadRewardedInterstitialAd();
    }

    @Override public void onAdUserRewarded() {

    }
}

Ad breaks

  1. Module access

In the application-level build.gradle file (usually app/build.gradle), complete the insertion of the interstitial module

dependencies {
    // bees sdk
    implementation 'io.github.beesads:sdk:2.0.0'
    // bees video 
    implementation 'io.github.beesads:video:1.1.0'
    
    // google ads 
    implementation 'com.google.android.gms:play-services-ads:23.5.0'
    
    // google ima 
    implementation 'androidx.browser:browser:1.6.0'
    implementation 'androidx.media:media:1.6.0'
    implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.36.0'
}
  1. API Introduction

BeesMediaAdLoader.Builder

Interstitial Ad Loader Construction Class

Method Name

Method Description

Builder(Context context, String adTagUrl)

Construction parameters. adTagUrl: advertising URL

setLanguage(String language)

Customize the local language, refer to the language region code Default language: "en"

setLoadTimeout(int timeout)

Custom timeout period, unit: milliseconds. The default time is 8*1000 milliseconds.

setAdLabelUI(boolean showAdLabelUI)

Show AD Tags are hidden by default

setCountdownUI(boolean showCountdownUI)

Show UI countdown hidden by default

setMuted(boolean mute)

Whether to request silent ads.

setPreload(boolean preload)

Whether to enable preloading. Enabled by default.

setContentProgressProvider(@NonNullMediaContentProgressProvider contentProgressProvider)

Set the content video progress provider (required for VAMP ads)

build()

Create an interstitial ad object

BeesMediaAdLoader

Mid-roll loader

Method Name

Method Description

loadAd(ViewGroup container, MediaAdPlayer mediaAdPlayer)

Load adscontainer: The container required to display ads. The parameter must be passed and must not be NULLmediaAdPlayer: The interface class that the custom player needs to implement

setAdListener(@Nullable BeesMediaAdListener listener)

Setting up ad listeners

setAdEventListener(@Nullable BeesMediaAdEventListener listener)

Set up ad event listeners

setAdOptionsCallback(@Nullable BeesMediaAdOptionsCallback callback)

Set the ad configuration callback. This allows developers to flexibly configure parameters at each stage before making an ad request.

isReady()

Is the ad ready?

destroy()

Advertisements are destroyed, releasing resources.

BeesMediaAd

Ad breaks

Method Name

Method Description

String getAdTagUrl()

Get ad URL parameters

MediaProgressUpdate getAdProgress()

Setting up ad listeners

registerFriendlyObstruction(@NonNull View view, @NonNull BeesMediaFriendlyType friendlyType, @Nullable String reason);

Register friendly controls. view: View (UI element) marked as friendly blocker friendlyType:

  1. VIDEO_CONTROLS: video controls, such as play, pause buttons, etc.;

  2. CLOSE_AD: close ad button;

  3. NOT_VISIBLE: invisible UI elements;

  4. OTHER: other types of UI elements.

reason: provide detailed reasons why this view does not prevent users from interacting with the ad

unregisterAllFriendlyObstructions()

Remove friendly control registration

start()

Advertisement playback

pause()

Ad pause

resume()

Advertisement recovery

destroy()

Advertisements are destroyed, releasing resources.

BeesMediaAdEventListener

Ad event listener

Method Name

Method Description

void onEvent(@NonNull Object event)

Ad time callback. event: refer to IMA ad event documentation

BeesMediaAdOptionsCallback

Ad settings callback

Method Name

Method Description

onAdsSetting(@NonNull Object configSetting)

For developers to customize ImaSdkSettings settings

onAdsRequest(@NonNull Object requestSetting)

Used by developers to customize AdsRequest settings

onAdsRender(@NonNull Object renderSetting)

For developers to customize AdsRenderingSettings settings

BeesMediaAdListener

Ad Listener

Method Name

Method Description

onAdLoadSuccess(@NonNull String adUrl)

Ad loading success callback. It will be triggered multiple times when loading VMAP ads.

onAdLoadFailed(@NonNull SdkError error)

Ad loading failure callback

onAdStarted()

Ad starts playing

onAdPaused()

After the ad is played, pause it

onAdResumed()

After the ad is paused, continue playing

onAdCompleted()

Advertisement playback completed

onAdAllCompleted()

All ads have been played

onAdError(@NonNull AdsError error)

Ad error

onAdSkipped()

Skippable ads, users click to skip

onAdTapped()

The video area is clicked

onAdClicked()

Ad clicked

onAdProgress(long progress, long duration)

Ad playback progress: Current playback progress Duration: Total duration of the ad Unit: milliseconds

onContentPause()

The video content is paused. The developer needs to complete the pause of the video content in this callback

onContentResume()

Video content is restored. Developers need to complete video content restoration in this callback

Code example:

// Build a video content progress provider
MediaContentProgressProvider contentProgressProvider = new MediaContentProgressProvider() {
    @NonNull @Override public MediaProgressUpdate getContentProgress() {
        return new MediaProgressUpdate();
    }
};

// Set ad video request parameters
BeesMediaAdLoader mediaAdLoader = new BeesMediaAdLoader.Builder(context, adTagUrl)
    .setMuted(true)
    .setPreload(false)
    .setLanguage(Locale.CHINA.getLanguage())
    .setLoadTimeout(60000)
    .setCountdown(false)
    .setAdLabel(false)
    .setContentProgressProvider(contentProgressProvider)
    .build();
    
// Set ad configuration callback
mediaAdLoader.setAdOptionsCallback(new MobileMediaOptionsCallback() {
    @Override public void onAdsSetting(@NonNull Object configSetting) {
        if (configSetting instanceof ImaSdkSettings) {
            Log.d("Demo", "ImaSdkSetting: " + configSetting);
            ((ImaSdkSettings) configSetting).setLanguage(Locale.JAPAN.getLanguage());
        }
    }

    @Override public void onAdsRequest(@NonNull Object requestSetting) {
        if (requestSetting instanceof AdsRequest) {
            Log.d("Demo", "AdsRequest: " + requestSetting);
        }
    }

    @Override public void onAdsRender(@NonNull Object renderSetting) {
        if (renderSetting instanceof AdsRenderingSettings) {
            Log.d("Demo", "AdsRenderingSetting: " + renderSetting);
        }
    }
});

// Set up ad event listeners
mediaAdLoader.setAdEventListener(event -> {
    if (event instanceof AdEvent) {
       
    }
});

// Monitor ad callbacks
mediaAdLoader.setAdListener(new BeesMediaAdListener() {
    @Override public void onAdLoadSuccess(@NonNull BeesMediaAd mediaAd) {
        // Advertisement loaded successfully, start playing
        if (mediaAdLoader != null && mediaAdLoader.isReady()) {
            mediaAd.registerFriendlyObstruction(playButton, BeesMediaFriendlyType.VIDEO_CONTROLS, "This is the video player play button")
            mediaAd.start();
        }
    }

    @Override public void onAdLoadFailed(@NonNull SdkError sdkError) {
        // Ad loading failed
    }

    @Override public void onAdClicked() {
        // Ad clicked
    }

    @Override public void onAdResumed() {
        // After the ad is paused, continue playing
    }

    @Override public void onAdPaused() {
        // After the ad is played, pause it
    }

    @Override public void onAdStarted() {
        // Ad starts playing
    }

    @Override public void onAdCompleted() {
        //Advertisement playback completed
    }

    @Override public void onAdAllCompleted() {
        // All ads have been played
    }

    @Override public void onAdError(@NonNull AdsError error) {
        // All ads have been played
    }

    @Override public void onAdSkipped() {
        // Skippable ads, users click to skip
    }

    @Override public void onAdTapped() {
        // The video area is clicked
    }

    @Override public void onAdProgress(long progress, long duration) {
        // Ad playback progress
    }

    @Override public void onContentPause() {
        // Video content pause
    }

    @Override public void onContentResume() {
        // Video content recovery
    }
});

// Loading Ads
mediaAdLoader.loadAd(uiContainer, new MediaAdPlayer());

// life cycle
@Override protected void onPause() {
    if (mediaAd != null) {
        mediaAd.pause();
    }
    super.onPause();
}

@Override protected void onResume() {
    super.onResume();
    if (mediaAd != null) {
        mediaAd.resume();
    }
}

@Override protected void onDestroy() {
    if (mediaAdLoader != null) {
        mediaAdLoader.destroy();
        mediaAdLoader = null;
    }
    if (mediaAd != null) {
        mediaAd.unregisterAllFriendlyObstructions();
        mediaAd.destroy();
        mediaAd = null;
    }
    super.onDestroy();
}

Privacy Compliance

GDPR

The General Data Protection Regulation (GDPR) is a set of data protection and privacy laws for all citizens of the European Union (EU) and the European Economic Area (EEA).

BeesPrivacySettings.setHasUserConsent(@NonNull Context context, boolean userConsent);

parameter:

Parameter name

Parameter meaning

context

Context

userConsent

ttrue: user agrees

false: user disagrees

CCPA

The California Consumer Privacy Act (CCPA) is the first comprehensive privacy law in the United States. It was signed into law in late June 2018 and provides a wide range of privacy rights to California consumers. Businesses governed by the CCPA will have a number of obligations to those consumers, including disclosures, consumer rights similar to the EU General Data Protection Regulation (GDPR), the right to “opt-out” of certain data transfers, and the right to “opt-in” for requests from minors.

BeesPrivacySettings.setDoNotSell(@NonNull Context context, boolean doNotSell);

parameter:

Parameter name

Parameter meaning

context

Context

doNotSell

true: do not report data false: report data

COPPA、GDPR Child

The U.S. Children’s Online Privacy Protection Act (COPPA) targets the online collection of personal information from children under the age of 13.

BeesPrivacySettings.setIsAgeRestrictedUser(@NonNull Context context, boolean isAgeRestrictedUser);

parameter:

Parameter name

Parameter meaning

context

Context

isAgeRestrictedUser

true: is an age-restricted user

false: is not an age-restricted user

Google Ads Content Ratings

BeesPrivacySettings.setMaxAdContentRating(@NonNull Context context, @Nullable String maxContentRating);

parameter:

Parameter name

Parameter meaning

context

Context

maxContentRating

All audiences: RequestConfiguration.MAX_AD_CONTENT_RATING_G

Teens: RequestConfiguration.MAX_AD_CONTENT_RATING_T

Adults: RequestConfiguration.MAX_AD_CONTENT_RATING_MA

Parental supervision required: RequestConfiguration.MAX_AD_CONTENT_RATING_PG

Debug Mode

BeesSdk.getInstance(context).setDebuggerEnabled(enabled);

Log Output

BeesSdk.getInstance(context).setLoggingEnabled(enabled);

Debug Mode

BeesSdk.getInstance(context).setMuted(muted);

Last updated