> For the complete documentation index, see [llms.txt](https://docs.blueseasx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blueseasx.com/android/interstitial-ads.md).

# Interstitial Ads

### **Step1. Load**

Before requesting ads, please ensure that the SDK has been initialized.

To request interstitial ads, declare a `MediationInfo` object. This object should include the ad mediation platform, the mediation version, and the BlueSea Adapter version used when requesting the ads. If you are integrating BlueSea SDK through your own mediation platform, it is recommended to declare the `MediationInfo` object and pass in the mediation information to facilitate monetization data management and channel monetization optimization. If you are integrating BlueSea SDK through third-party mediations like MAX, LevelPlay, etc., you can skip this step.

```
MediationInfo mediationInfo = new MediationInfo("<in house or mediation name>","<mediation-version-name>", "<adapter-version-code>");
```

* `<in house or mediation name>`: Pass the value as "in-house" or the specific mediation platform name.
* `<mediation-version-name>`: Pass the version number of the mediation SDK.
* `<adapter-version-code>`: Pass the version number of the adapter.

Call the `loadInterstitialAd()` method, pass the ad's Placement ID, and initiate the ad request:

```
BlueseasxSDK.loadInterstitialAd("<BlueSea-pid>", mediationInfo, new AdLoadCallback<InterstitialAd>() {
   @Override
   public void onAdLoadError(@NonNull AdError error) {
       Log.d(TAG, "loadInterstitialAd error, code=" + error.getCode() + ", message=" + error.getMessage());
   }

   @Override
   public void onAdLoaded(@NonNull InterstitialAd ad) {
       Log.d(TAG, "loadInterstitialAd success");
       mInterstitialAd = ad;
   }
});
```

`AdLoadCallback<InterstitialAd>` callback:

* `onAdLoadError(AdError error)`: Indicates that no ads were filled. This may be due to the advertiser not bidding or other issues. You can check the error code and message by using `AdError.getCode()` and `AdError.getMessage()`. For details on error codes, refer to XXX
* `onAdLoaded(InterstitialAd ad)`: Indicates that the ad was successfully filled, and returns an instance of the `InterstitialAd` object.

The following example shows how to fully load an interstitial ad in the `onCreate()` method of an Activity:

```
...
import com.blueseasx.sdk.AdError;
import com.blueseasx.sdk.AdLoadCallback;
import com.blueseasx.sdk.InterstitialAd;
import com.blueseasx.sdk.MediationInfo;
import com.blueseasx.sdk.AdListener;

public class MainActivity extends Activity {

    InterstitialAd mInterstitialAd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        ...
       MediationInfo mediationInfo = new MediationInfo("<in house or mediation name>","<mediation-version-name>", "<adapter-version-code>");
        BlueseasxSDK.loadInterstitialAd("<BlueSea-pid>", mediationInfo, new AdLoadCallback<InterstitialAd>() {
         @Override
         public void onAdLoadError(@NonNull AdError error) {
           Log.d(TAG, "loadInterstitialAd error, pid=" + pid + ", code=" + error.getCode() + ", message=" + error.getMessage());
      }

       @Override
       public void onAdLoaded(@NonNull InterstitialAd ad) {
         Log.d(TAG, "loadInterstitialAd success");
         mInterstitialAd = ad;
       }
     });
    }
}
```

### **Step2. Show**

After the `onAdLoaded(InterstitialAd ad)` callback, register the ad listener using the `InterstitialAd.setAdListener()` method:

```
mInterstitialAd.setAdListener(new AdListener() {
    @Override
    public void onAdDisplayFailed(@NonNull AdError error) {
        // something wrong when displaying the ad
    }

    @Override
    public void onAdDisplayed() {
        // an ad impression occurs
    }

    @Override
    public void onAdClicked() {
        // the ad is clicked by user
    }

    @Override
    public void onAdOpened() {
        // the ad overlays the screen
    }

    @Override
    public void onAdClosed() {
        // the full screen ad is closed
    }
});
```

Before displaying the ad, use the `InterstitialAd.isExpired()` method to check if the ad has expired (the ad's validity period is typically 60 minutes). If the ad has expired, you can request a new one. If it has not expired, you can use the `InterstitialAd.show(Activity activity)` method to display the interstitial ad:

```
mInterstitialAd.show(activity);
```

### **Step3. Destroy**

The SDK will automatically destroy the ad after detecting that the user has closed it.
