| Abstract Method | Parameter Description | Return Value | Purpose | Required |
|---|---|---|---|---|
| isAdReady | - | boolean | Used to determine whether the custom ad platform's Interstitial Ad is in a ready state. | Yes |
| show | Activity activity: The activity context. | void | Implement the logic for displaying the custom ad platform's Interstitial Ad. | Yes |
Use the CustomInterstitialEventListene member variable of CustomInterstitialAdapter to implement ad event callbacks.
| Callback Method | Parameter Description | Description |
|---|---|---|
| onInterstitialAdVideoStart | - | Callback to the developer when ad video playback starts. |
| onInterstitialAdVideoEnd | - | Callback to the developer when ad video playback ends. |
| onInterstitialAdVideoError | String errorCode: Error code info String errorMsg: Detailed error info | Callback to the developer when ad video playback fails. |
| onInterstitialAdClose | - | Callback to the developer when the ad page is closed. |
| onInterstitialAdClicked | - | Callback to the developer when the ad is clicked. |
| onInterstitialAdShow | - | Callback to the developer when the ad page is displayed. |
Note: When using the member variable CustomInterstitialEventListene, null-check handling is required, because the Mediation SDK may internally reclaim this Listener object.
public class FacebookInterstitialAdapter extends CustomInterstitialAdapter {
InterstitialAd mInterstitialAd;
String mUnitid;
String mPayload;
/***
* load ad
*/
private void startLoad(final Context context) {
final InterstitialAdListener interstitialAdListener = new InterstitialAdListener() {
@Override
public void onError(Ad ad, AdError adError) {
if (mLoadListener != null) {
mLoadListener.onAdLoadError(adError.getErrorCode() + "", "" + adError.getErrorMessage());
}
}
@Override
public void onAdLoaded(Ad ad) {
if (mLoadListener != null) {
mLoadListener.onAdCacheLoaded();
}
}
@Override
public void onAdClicked(Ad ad) {
if (mImpressListener != null) {
mImpressListener.onInterstitialAdClicked();
}
}
@Override
public void onLoggingImpression(Ad ad) {
}
@Override
public void onInterstitialDisplayed(Ad ad) {
if (mImpressListener != null) {
mImpressListener.onInterstitialAdShow();
}
}
@Override
public void onInterstitialDismissed(Ad ad) {
if (mImpressListener != null) {
mImpressListener.onInterstitialAdClose();
}
}
};
mInterstitialAd = new InterstitialAd(context.getApplicationContext(), mUnitid);
// Load a new interstitial.
final InterstitialAd.InterstitialAdLoadConfigBuilder adConfig = mInterstitialAd.buildLoadAdConfig()
.withAdListener(interstitialAdListener);
if (!TextUtils.isEmpty(mPayload)) {
adConfig.withBid(mPayload);
}
mInterstitialAd.loadAd(adConfig.build());
}
@Override
public void destory() {
try {
if (mInterstitialAd != null) {
mInterstitialAd.setAdListener(null);
mInterstitialAd.destroy();
mInterstitialAd = null;
}
} catch (Exception e) {
}
}
@Override
public void loadCustomNetworkAd(Context context, Map<String, Object> serverExtras, Map<String, Object> localExtras) {
if (serverExtras.containsKey("unit_id")) {
mUnitid = (String) serverExtras.get("unit_id");
} else {
if (mLoadListener != null) {
mLoadListener.onAdLoadError("", "facebook sdkkey is empty.");
}
return;
}
if (serverExtras.containsKey("payload")) {
mPayload = serverExtras.get("payload").toString();
}
FacebookInitManager.getInstance().initSDK(context.getApplicationContext(), serverExtras);
startLoad(context);
}
@Override
public boolean isAdReady() {
if (mInterstitialAd == null || !mInterstitialAd.isAdLoaded()) {
return false;
}
if (mInterstitialAd.isAdInvalidated()) {
return false;
}
return true;
}
@Override
public boolean setUserDataConsent(Context context, boolean isConsent, boolean isEUTraffic) {
return false;
}
@Override
public void show(Activity activity) {
if (mInterstitialAd != null) {
mInterstitialAd.show();
}
}
@Override
public String getNetworkSDKVersion() {
return FacebookInitManager.getInstance().getNetworkVersion();
}
@Override
public String getNetworkName() {
return FacebookInitManager.getInstance().getNetworkName();
}
@Override
public String getNetworkPlacementId() {
return mUnitid;
}
}