Interstitial ads

An interstitial ad is a configurable ad that covers the entire screen and responds to clicks.

To enable advertising:

Creating InterstitialAd

  1. Create an object of the InterstitialAd class. This object can only be created programmatically.

    mInterstitialAd = new InterstitialAd(this);
  2. Set the Block ID using the setBlockId method.

    mInterstitialAd.setBlockId(BLOCK_ID);

    BlockId is a unique identifier in the R-M-XXXXXX-Y format, which is assigned in the Partner interface.

  3. After creating and configuring an instance of the InterstitialAd class, you can set an InterstitialEventListener on the ad object for tracking events (opening or closing the ad, exiting the app, and loading the ad successfully or unsuccessfully).

Loading ads

After creating and configuring an instance of the AdView class, load ads.

To load an ad, use the loadAd method, which takes the AdRequest object as a parameter:
mInterstitialAd.loadAd(adRequest);
Copied to clipboard

About loading ads

Use the AdRequest object to transmit the code received in the ADFOX interface (for more information, see the Help for ADFOX Mobile):
// Code from the ADFOX interface for working with direct campaigns.
Map<String, String=""> parameters = new HashMap<String, String="">();
parameters.put("adf_ownerid", "example");
parameters.put("adf_p1", "example");
parameters.put("adf_p2", "example");
parameters.put("adf_pfc", "example");
parameters.put("adf_pfb", "example");
parameters.put("adf_plp", "example");
parameters.put("adf_pli", "example");
parameters.put("adf_pop", "example");
parameters.put("adf_pt", "example");
parameters.put("adf_pd", "example");
parameters.put("adf_pw", "example");
parameters.put("adf_pv", "example");
parameters.put("adf_prr", "example");
parameters.put("adf_pdw", "example");
parameters.put("adf_pdh", "example");
parameters.put("adf_puid1", "example");

final AdRequest adRequest = AdRequest.builder().withParameters(parameters).build();
Copied to clipboard

Displaying ads

An interstitial ad is loaded in the background immediately after the loadAd call. To display an interstitial ad, you must call the show method.

We recommend checking whether the ad has actually loaded. To do this, call the isLoaded method.

Note.

You don't need to check this if the show method is called after the onInterstitialLoaded callback, which indicates that loading has finished.

Example of working with interstitial ads

The following code demonstrates creating and configuring the InterstitialAd object, registering a listener, and loading and displaying the interstitial ad:

...
public class InterstitialExample extends Activity {
    ...
    private static final String BLOCK_ID = "YOUR_BLOCK_ID";
    private InterstitialAd mInterstitialAd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        // Creating an InterstitialAd instance.
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setBlockId(BLOCK_ID);

        // Code from the ADFOX interface for working with direct campaigns.
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("adf_ownerid", "example");
        parameters.put("adf_p1", "example");
        parameters.put("adf_p2", "example");
        parameters.put("adf_pfc", "example");
        parameters.put("adf_pfb", "example");
        parameters.put("adf_plp", "example");
        parameters.put("adf_pli", "example");
        parameters.put("adf_pop", "example");
        parameters.put("adf_pt", "example");
        parameters.put("adf_pd", "example");
        parameters.put("adf_pw", "example");
        parameters.put("adf_pv", "example");
        parameters.put("adf_prr", "example");
        parameters.put("adf_pdw", "example");
        parameters.put("adf_pdh", "example");
        parameters.put("adf_puid1", "example");

        // Creating an ad targeting object.
        final AdRequest adRequest = AdRequest.builder().withParameters(parameters).build();

        // Registering a listener to track events in the ad.
        mInterstitialAd.setInterstitialEventListener(new InterstitialEventListener.SimpleInterstitialEventListener() {
            @Override
            public void onInterstitialLoaded() {
                mInterstitialAd.show();
            }
        });

        // Loading ads.
        mInterstitialAd.loadAd(adRequest);
    }
}
Copied to clipboard

If an ad is integrated this way, the ad block appears after the app starts:

To see how the ad will be displayed in the app, use a demo Block ID:
  • R-M-DEMO-240x400-context
  • R-M-DEMO-320x480
  • R-M-DEMO-400x240-context
  • R-M-DEMO-480x320