H5AdsWebViewClient

@RequiresApi(api = VERSION_CODES.LOLLIPOP)
class H5AdsWebViewClient : WebViewClient


A WebViewClient that intercepts and handles H5 ad requests. To use this, set this as the client of the WebView that contains the web apps that will be making H5 ad requests.

IMPORTANT: This WebViewClient cannot be used for multiple WebViews. Every new WebView that will support H5 ads must use a new H5AdsWebViewClient.

Example code:

public void onCreate(Bundle savedInstanceState) {
  ...

  // Initialize early to reduce latency on the session's first ad request.
  MobileAds.initialize(this);

  WebView myWebView = findViewById(R.id.my_webview);

  // JavaScript must be enabled.
  WebSettings settings = myWebView.getSettings();
  settings.setJavaScriptEnabled(true);

  H5AdsWebViewClient h5Client = new H5AdsWebViewClient(this, myWebView);

  // (Optional) any existing WebViewClient
  WebViewClient myClient = ...;
  h5Client.setDelegateWebViewClient(myClient);

  webView.setWebViewClient(h5Client);
}

Summary

Public constructors

H5AdsWebViewClient(context: Context!, webView: WebView!)

Constructor for H5AdsWebViewClient.

Public functions

Unit

Destroys all ads being managed by H5 ads.

WebViewClient?

Gets the delegate WebViewClient.

Unit

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient.

Protected functions

WebViewClient!

Inherited functions

From android.webkit.WebViewClient
Unit
Unit
Unit
Unit
Unit
Unit
onPageStarted(p: WebView!, p1: String!, p2: Bitmap!)
Unit
Unit
Unit
onReceivedHttpAuthRequest(
    p: WebView!,
    p1: HttpAuthHandler!,
    p2: String!,
    p3: String!
)
Unit
onReceivedHttpError(
    p: WebView!,
    p1: WebResourceRequest!,
    p2: WebResourceResponse!
)
Unit
onReceivedLoginRequest(p: WebView!, p1: String!, p2: String!, p3: String!)
Unit
Boolean
Unit
onSafeBrowsingHit(
    p: WebView!,
    p1: WebResourceRequest!,
    p2: Int,
    p3: SafeBrowsingResponse!
)
Unit
onScaleChanged(p: WebView!, p1: Float, p2: Float)
Unit

This function is deprecated.

Unit
WebResourceResponse!
Boolean
Boolean

Public constructors

H5AdsWebViewClient

H5AdsWebViewClient(context: Context!, webView: WebView!)

Constructor for H5AdsWebViewClient.

Parameters
context: Context!

An activity or application context.

webView: WebView!

The WebView that will be associated with this H5AdsWebViewClient. JavaScript must be enabled on the WebView.

Public functions

clearAdObjects

fun clearAdObjects(): Unit

Destroys all ads being managed by H5 ads.

Note: This method has no effect on any ads created by the non-H5 AdMob API, such as com.google.android.gms.ads.interstitial.InterstitialAd and com.google.android.gms.ads.rewarded.RewardedAd.

getDelegateWebViewClient

fun getDelegateWebViewClient(): WebViewClient?

Gets the delegate WebViewClient.

setDelegateWebViewClient

fun setDelegateWebViewClient(delegate: WebViewClient?): Unit

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient.

Protected functions

getDelegate

protected fun getDelegate(): WebViewClient!