Class AdView

com.yandex.mobile.ads

java.lang.Object ⇽ AdView

public class AdView

A class for displaying banner ads.

Constructors

AdView(@NonNull final Context context)

Creates an object of the AdView class programmatically.

AdView(final Context context, final AttributeSet attrs)

Creates an object of the AdView class from an XML file.

AdView(final Context context, final AttributeSet attrs, final int defStyleAttr)

Creates an object of the AdView class from an XML file.

Methods

AdViewController createViewController(@NonNull final Context context, @NonNull final BannerAdListener bannerAdListener)
void destroy()

Deletes an object of the AdView class and releases all resources in use.

AdEventListener getAdEventListener()

Returns an object of the AdEventListener class.

AdSize getAdSize()

Returns the size of banner ads.

String getBlockId()

Returns the unique ID of the ad placement.

VideoController getVideoController()

Returns an object of the VideoController class, which manages the video content in an ad.

void loadAd(final AdRequest adRequest)

Starts ad loading in the background.

void pause()

Pauses banner ads.

void resume()

Resumes showing banner ads.

void setAdEventListener(final AdEventListener adEventListener)

Sets an object of the AdEventListener class.

void setAdSize(@Nullable final AdSize adSize)

Sets the size of banner ads.

void setAutoRefreshEnabled(final boolean enabled)

Toggles the mode for auto-refreshing banner ads.

void setBlockId(final String blockId)

Sets the unique ID of the ad space.

void shouldOpenLinksInApp(final boolean shouldOpenLinksInApp)

Determines how to open links from the app.

Constructor Detail

AdView

public AdView (@NonNull final Context context)

Creates an object of the AdView class programmatically.

Parameters:
context

An object of the Context system class.

AdView

public AdView (final Context context, final AttributeSet attrs)

Creates an object of the AdView class from an XML file.

Parameters:
context

An object of the Context system class.

attrs

Attributes that are defined when creating the AdView object via a representation in an XML file.

AdView

public AdView (final Context context, final AttributeSet attrs, final int defStyleAttr)

Creates an object of the AdView class from an XML file.

Parameters:
context

An object of the Context system class.

attrs

Attributes that are defined when creating the AdView object via a representation in an XML file.

defStyleAttr

An attribute that contains a reference to a style resource for view. The default values are described in the resource. The default values are described in the resource.

Method Detail

createViewController

protected AdViewController createViewController (@NonNull final Context context, @NonNull final BannerAdListener bannerAdListener)

destroy

public void destroy ()

Deletes an object of the AdView class and releases all resources in use.

Note.

Don't use objects of the AdView class after calling this method.

getAdEventListener

public AdEventListener getAdEventListener ()

Returns an object of the AdEventListener class.

Returns:

An object of the AdEventListener class.

getAdSize

public AdSize getAdSize ()

Returns the size of banner ads.

Returns:

The size of banner ads.

getBlockId

public String getBlockId ()

Returns the unique ID of the ad placement.

Returns:

Unique ID of the ad placement.

getVideoController

public VideoController getVideoController ()

Returns an object of the VideoController class, which manages the video content in an ad.

Returns:

An object of the VideoController class.

loadAd

public void loadAd (final AdRequest adRequest)

Starts ad loading in the background.

Note.

The ID of the advertising block blockID must be passed before calling this method.

Parameters:
adRequest

An object of the AdRequest class with data for a targeted ad request.

pause

public void pause ()

Pauses banner ads.

resume

public void resume ()

Resumes showing banner ads.

setAdEventListener

public void setAdEventListener (final AdEventListener adEventListener)

Sets an object of the AdEventListener class.

Parameters:
adEventListener

An object of the AdEventListener class, which will receive notifications about events occurring during the banner ad lifecycle.

setAdSize

public void setAdSize (@Nullable final AdSize adSize)

Sets the size of banner ads.

Parameters:
adSize

The size of banner ads from the AdSize class.

Throws:

throwIllegalArgumentIfEmpty

An empty size or the null value is set for the ad block in the current object of the AdSize class.

throwIllegalArgumentIfNotEmpty

The ad block size is already set for the current object of the AdSize class.

setAutoRefreshEnabled

public void setAutoRefreshEnabled (final boolean enabled)

Toggles the mode for auto-refreshing banner ads.

Parameters:
enabled
Mode for automatically refreshing banner ads. Acceptable values:
  • true — Auto-refresh enabled.

  • false — Auto-refresh disabled.

The default value is true.

setBlockId

public void setBlockId (final String blockId)

Sets the unique ID of the ad space.

Parameters:
blockId

Unique ID of the ad placement.

Throws:

throwIllegalArgumentIfEmpty

An empty blockId or the null value is set for the current object of the AdView class.

throwIllegalArgumentIfNotEmpty

The blockId is already set for the current object of the AdView class.

shouldOpenLinksInApp

public void shouldOpenLinksInApp (final boolean shouldOpenLinksInApp)

Determines how to open links from the app.

Parameters:
shouldOpenLinksInApp
How to open links from the app. Acceptable values:
  • true — Open links in the in-app browser.

  • false — Open links in the device browser.

The default value is false.