Class AdRequest

java.lang.Object
com.codename1.ads.AdRequest

public class AdRequest extends java.lang.Object

Optional targeting metadata attached to an ad load. Build one with the fluent setters and pass it to a load method, or omit it entirely to load with defaults:

interstitial.load(new AdRequest()
        .addKeyword("games")
        .contentUrl("https://example.com/level"));

An AdRequest is immutable once a load begins; reuse or discard freely.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addKeyword(String keyword)
    Adds a keyword used to target the ad.
    contentUrl(String contentUrl)
    Sets a URL describing the content the ad will appear next to, used for brand safety and contextual targeting.
    The content URL associated with this request, may be null.
    The keywords associated with this request, never null.
    The keywords as a comma separated string, used by native bridges.
    boolean
    True when non personalized ads were explicitly requested.
    nonPersonalized(boolean nonPersonalized)
    Requests non-personalized ads regardless of the user's consent state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AdRequest

      public AdRequest()
  • Method Details

    • addKeyword

      public AdRequest addKeyword(String keyword)

      Adds a keyword used to target the ad.

      Parameters
      • keyword: a keyword describing the current content
      Returns

      this request for chaining

    • getKeywords

      public List<String> getKeywords()
      The keywords associated with this request, never null.
    • getKeywordString

      public String getKeywordString()
      The keywords as a comma separated string, used by native bridges. Returns an empty string when no keywords were set.
    • contentUrl

      public AdRequest contentUrl(String contentUrl)

      Sets a URL describing the content the ad will appear next to, used for brand safety and contextual targeting.

      Parameters
      • contentUrl: the URL of the surrounding content
      Returns

      this request for chaining

    • getContentUrl

      public String getContentUrl()
      The content URL associated with this request, may be null.
    • nonPersonalized

      public AdRequest nonPersonalized(boolean nonPersonalized)

      Requests non-personalized ads regardless of the user's consent state. This is normally driven automatically by AdConsent; set it explicitly only when you have your own consent mechanism.

      Parameters
      • nonPersonalized: true to request non personalized ads
      Returns

      this request for chaining

    • isNonPersonalized

      public boolean isNonPersonalized()
      True when non personalized ads were explicitly requested.