Request interstitial ads

Requesting interstitials is an asynchronous operation. We recommend doing this close to the actual point of showing an ad to the user, but not immediately before, as the process of requesting ads can take some time. Additionally, some networks are pre-caching the interstitial, and therefore by allowing for some time between the request and display of the ad you can be sure that the user experience will be the best.

  1. Before starting with the integration of the interstitial ads please make sure you have started the Fyber SDK with your appID (and optionally user ID) as described in the “Getting started with Fyber SDK” guide.

  2. Import the required packages

     import com.fyber.requesters.InterstitialRequester;
     import com.fyber.requesters.RequestCallback;
    
  3. Make sure the interstitial activity is defined in your AndroidManifest.xml file. If you are using Gradle, you can skip this step:

	<manifest xmlns:android="http://schemas.android.com/apk/res/android">

	    [...]

	    <uses-permission android:name="android.permission.INTERNET" />
	    <application>

	        [...]

	    <activity
		 android:name="com.fyber.ads.interstitials.InterstitialActivity"
		 android:configChanges="screenSize|orientation"
	   	 android:theme="@android:style/Theme.Translucent" />

	    </application>

	</manifest>
  1. Invoke the following method:
InterstitialRequester.create(requestCallback)
        .request(activity);

Where requestCallback will be an instance of RequestCallback. This defines the following methods:

RequestCallback requestCallback = new RequestCallback() {
            @Override
            public void onAdAvailable(Intent intent) {
            }

            @Override
            public void onAdNotAvailable(AdFormat adFormat) {
            }

            @Override
            public void onRequestError(RequestError requestError) {
            }
        };

After you call request(context);, the RequestCallback will be notified of the result.

The appropriate method of the RequestCallback interface is called. If an offer is available, you can store the received Intent in order to start it later or start it right away with the startActivityForResult method.

Note: We recommend requesting the interstitial close to the actual point of showing an ad to the user, but not immediately before, as the process of requesting ads can take some time.