java.lang.Object | |
↳ | com.google.android.gms.ads.doubleclick.PublisherInterstitialAd |
Full-screen interstitial ads for use with DoubleClick for Publishers. The ad unit ID must be set
prior to calling loadAd(PublisherAdRequest)
.
Sample code:
public class MyActivity extends Activity { private PublisherInterstitialAd mPublisherInterstitialAd; private Button mNextLevelButton; private TextView mTextView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create an interstitial ad. When a natural transition in the app occurs (such as a // level ending in a game), show the interstitial. In this simple example, the press of a // button is used instead. // // If the button is clicked before the interstitial is loaded, the user should proceed to // the next part of the app (in this case, the next level). // // If the interstitial is finished loading, the user will view the interstitial before // proceeding. mPublisherInterstitialAd = new PublisherInterstitialAd(this); mPublisherInterstitialAd.setAdUnitId("myAdUnitId"); // Create an ad request. PublisherAdRequest.Builder publisherAdRequestBuilder = new PublisherAdRequest.Builder(); // Optionally populate the ad request builder. publisherAdRequestBuilder.addTestDevice(PublisherAdRequest.DEVICE_ID_EMULATOR); // Set an AdListener. mPublisherInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { Toast.makeText(MyActivity.this, "The interstitial is loaded", Toast.LENGTH_SHORT).show(); } @Override public void onAdClosed() { // Proceed to the next level. goToNextLevel(); } }); // Start loading the ad now so that it is ready by the time the user is ready to go to // the next level. mPublisherInterstitialAd.loadAd(publisherAdRequestBuilder.build()); // Create the button to go to the next level. mNextLevelButton = new Button(this); mNextLevelButton.setText("Next Level"); mNextLevelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Show the interstitial if it is ready. Otherwise, proceed to the next level // without ever showing it. if (mPublisherInterstitialAd.isLoaded()) { mPublisherInterstitialAd.show(); } else { // Proceed to the next level. goToNextLevel(); } } }); // Add the next level button to the layout. LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(mNextLevelButton); // Create a TextView to display the current level. mTextView = new TextView(this); mTextView.setText("Level 1"); layout.addView(mTextView); setContentView(layout); } public void goToNextLevel() { // Show the next level (and disable the next level button since there are no more levels. mNextLevelButton.setEnabled(false); mTextView.setText("Level 2"); } }
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct an
PublisherInterstitialAd . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the
AdListener for this PublisherInterstitialAd . | |||||||||||
Returns the ad unit ID.
| |||||||||||
Returns the
AppEventListener for this PublisherInterstitialAd . | |||||||||||
Returns the mediation adapter class name.
| |||||||||||
Returns the
OnCustomRenderedAdLoadedListener for this PublisherInterstitialAd . | |||||||||||
Returns
true if the ad was successfully loaded and is ready to be shown. | |||||||||||
Returns
true if the ad is loading. | |||||||||||
Start loading the ad on a background thread.
| |||||||||||
Sets an
AdListener for this PublisherInterstitialAd . | |||||||||||
Sets the ad unit ID.
| |||||||||||
Sets an
AppEventListener for this PublisherInterstitialAd . | |||||||||||
Attach a
Correlator to this PublisherInterstitialAd . | |||||||||||
Sets a flag that controls if this interstitial object will be displayed in immersive mode.
| |||||||||||
Sets an
OnCustomRenderedAdLoadedListener for this PublisherInterstitialAd . | |||||||||||
Show the interstitial ad.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Construct an PublisherInterstitialAd
.
Parameters | |
---|---|
context |
Context :
The Context the PublisherInterstitialAd is running in.
|
Returns the AdListener
for this PublisherInterstitialAd
.
Returns | |
---|---|
AdListener |
Returns the ad unit ID.
Returns | |
---|---|
String |
Returns the AppEventListener
for this PublisherInterstitialAd
.
Returns | |
---|---|
AppEventListener |
Returns the mediation adapter class name. In the case of a mediated ad response, this is the
name of the class that was responsible for performing the ad request and rendering the ad. For
non-mediated responses, this value will be null
.
Returns | |
---|---|
String |
Returns the OnCustomRenderedAdLoadedListener
for this PublisherInterstitialAd
.
Returns | |
---|---|
OnCustomRenderedAdLoadedListener |
Returns true
if the ad was successfully loaded and is ready to be shown.
Returns | |
---|---|
boolean |
Returns true
if the ad is loading.
Returns | |
---|---|
boolean |
Start loading the ad on a background thread.
Parameters | |
---|---|
publisherAdRequest |
PublisherAdRequest
|
Throws | |
---|---|
IllegalStateException |
If the the ad unit ID has not been set. |
Sets an AdListener
for this PublisherInterstitialAd
.
Parameters | |
---|---|
adListener |
AdListener
|
Sets the ad unit ID.
Parameters | |
---|---|
adUnitId |
String
|
Throws | |
---|---|
IllegalStateException |
If the ad unit ID was already set. |
Sets an AppEventListener
for this PublisherInterstitialAd
.
Parameters | |
---|---|
appEventListener |
AppEventListener
|
Attach a Correlator
to this PublisherInterstitialAd
. Passing a null value to
detach any Correlator
from this PublisherInterstitialAd
.
Parameters | |
---|---|
correlator |
Correlator
|
Sets a flag that controls if this interstitial object will be displayed in immersive mode. Call
this method before show()
to affect subsequent interstitial
ads. During show()
, if this flag is on and immersive mode is
supported, SYSTEM_UI_FLAG_IMMERSIVE_STICKY & SYSTEM_UI_FLAG_HIDE_NAVIGATION will be turned on
for interstitial ad.
Parameters | |
---|---|
immersiveModeEnabled |
boolean
|
Sets an OnCustomRenderedAdLoadedListener
for this PublisherInterstitialAd
.
Parameters | |
---|---|
onCustomRenderedAdLoadedListener |
OnCustomRenderedAdLoadedListener
|
Show the interstitial ad.