// to prefetch ad
try {
interstitialAdDispatcher.prefetchAd(new InterstitialAd.InterstitialAdListener() {
@Override
public void onAdLoaded(InterstitialAd ad) {
SampleAppLog.d(TAG, "prefetchAdRequest success");
}
@Override
public void onAdFailedToLoad(int errorCode) {
SampleAppLog.d(TAG, "prefetchAdRequest Failed - " + errorCode);
}
});
} catch (AdException e) {
SampleAppLog.e(<em>TAG</em>, "prefetchAd returned error " + e.getMessage());
}
// to load and show ad
try {
interstitialAdDispatcher.loadAndShowAd(adListener, interstitialAdLifecycleListener);
} catch (AdException e) {
SampleAppLog.e(TAG, "loadAndShowAd returned error " + e.getMessage());
}
To load and show an ad:
// to load and show ad
try {
interstitialAdDispatcher.loadAndShowAd(adListener, interstitialAdLifecycleListener);
} catch (AdException e) {
SampleAppLog.e(TAG, "loadAndShowAd returned error " + e.getMessage());
}
Listen for ad events
To further customize the behavior of your ad, you can receive events during the ad’s lifecycle: loading, opening, closing, error and so on. You can listen for these events through the following listeners.
AdListener
Set the InterstitialAdListener to receive the video ad loading status. This is used as the first parameter of prefetchAd() or loadAndShowAd():
InterstitialAd.InterstitialAdListener adListener = new InterstitialAd.InterstitialAdListener() {
@Override
public void onAdLoaded(InterstitialAd ad) {
SampleAppLog.d(TAG, "onAdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
SampleAppLog.e(TAG, "onAdFailedToLoad " + errorCode);
}
};
The details of the AdListener are as follows:
Name
Detail
1
onAdLoaded
When an Ad has successfully finished loading.
2
onAdFailedToLoad
When an Ad has failed to load.
(Include the error parameter of type ‘ErrorCode’ which describes the error that has occurred.)
AdLifeCycleListener
Set the InterstitialAdLifecycleListener to get the status of an ad. This is used as the second parameter of loadAndShowAd().
private InterstitialAdLifecycleListener interstitialAdLifecycleListener = >new InterstitialAdLifecycleListener() {
@Override
public void onAdClosed() {
AdAppLog.d(TAG, "onAdClosed");
// Add your codes
}
@Override<
public void onAdStarted() {
AdAppLog.d(TAG, "onAdStarted");
// Add your codes
}
@Override
public void onAdCompleted() {
AdAppLog.d(TAG, "onAdCompleted");
// Add your codes
}
@Override
public void onAdSkipTimeElapsed() {
AdAppLog.d(TAG, "onAdSkipTimeElapsed");
// Add your codes
}
@Override
public void onAdPlaybackError() {
AdAppLog.d(TAG, "onAdPlaybackError");
// Add your codes
}
};
The details of the video listener are as follows (get the status of an ad using InterstitialAdLifecycleListener when the ad finishes):
Name
Detail
1
OnAdStarted
When starting the playback of a video ad.
For example, do not provide a reward because the ad is closed before the playback is started, that is, if this listener is not called before the ad is closed.
2
OnAdCompleted
When the playback of a video ad is completed. Called when the user should be rewarded.
For example, provide a reward because the video ad is closed after the playback is completed if this listener is called before the ad is closed.
3
OnAdSkipTimeElapsed
When the playback is done until skip time (5 secs) of the interstitial video ad
Warning: This event does not occur in the rewarded video ad.
For example, a game can start when this listener is called before the interstitial video ad is closed because playback of the video ad has reached or exceeded the skip time.
4
OnAdPlaybackError
When a playback error occurs.
For example, you can determine whether to provide reward or not when a playback error occurs.
5
OnAdClosed
When the ad is closed.
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.