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.

Unit
doUpdateVisitedHistory(view: WebView!, url: String!, isReload: Boolean)
WebViewClient?

Gets the delegate WebViewClient.

Unit
onFormResubmission(view: WebView!, dontResend: Message!, resend: Message!)
Unit
onLoadResource(view: WebView!, url: String!)
Unit
@RequiresApi(api = VERSION_CODES.M)
onPageCommitVisible(view: WebView!, url: String!)
Unit
onPageFinished(view: WebView!, url: String!)
Unit
onPageStarted(view: WebView!, url: String!, favicon: Bitmap!)
Unit
Unit
@RequiresApi(api = VERSION_CODES.M)
onReceivedError(
    view: WebView!,
    request: WebResourceRequest!,
    error: WebResourceError!
)
Unit
onReceivedError(
    view: WebView!,
    errorCode: Int,
    description: String!,
    failingUrl: String!
)

This function is deprecated.

Unit
onReceivedHttpAuthRequest(
    view: WebView!,
    handler: HttpAuthHandler!,
    host: String!,
    realm: String!
)
Unit
@RequiresApi(api = VERSION_CODES.M)
onReceivedHttpError(
    view: WebView!,
    request: WebResourceRequest!,
    errorResponse: WebResourceResponse!
)
Unit
onReceivedLoginRequest(
    view: WebView!,
    realm: String!,
    account: String?,
    args: String!
)
Unit
onReceivedSslError(
    view: WebView!,
    handler: SslErrorHandler!,
    error: SslError!
)
Boolean
@RequiresApi(api = VERSION_CODES.O)
onRenderProcessGone(view: WebView!, detail: RenderProcessGoneDetail!)
Unit
@RequiresApi(api = VERSION_CODES.O_MR1)
onSafeBrowsingHit(
    view: WebView!,
    request: WebResourceRequest!,
    threatType: Int,
    callback: SafeBrowsingResponse!
)
Unit
onScaleChanged(view: WebView!, oldScale: Float, newScale: Float)
Unit
onTooManyRedirects(view: WebView!, cancelMsg: Message!, continueMsg: Message!)

This function is deprecated.

Unit
Unit

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient.

WebResourceResponse?
WebResourceResponse?

This function is deprecated.

Boolean
Boolean
@RequiresApi(api = VERSION_CODES.N)
shouldOverrideUrlLoading(view: WebView!, request: WebResourceRequest!)
Boolean

This function is deprecated.

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 and .

doUpdateVisitedHistory

fun doUpdateVisitedHistory(view: WebView!, url: String!, isReload: Boolean): Unit

getDelegateWebViewClient

fun getDelegateWebViewClient(): WebViewClient?

Gets the delegate WebViewClient.

onFormResubmission

fun onFormResubmission(view: WebView!, dontResend: Message!, resend: Message!): Unit

onLoadResource

fun onLoadResource(view: WebView!, url: String!): Unit

onPageCommitVisible

@RequiresApi(api = VERSION_CODES.M)
fun onPageCommitVisible(view: WebView!, url: String!): Unit

onPageFinished

fun onPageFinished(view: WebView!, url: String!): Unit

onPageStarted

fun onPageStarted(view: WebView!, url: String!, favicon: Bitmap!): Unit

onReceivedClientCertRequest

fun onReceivedClientCertRequest(view: WebView!, request: ClientCertRequest!): Unit

onReceivedError

@RequiresApi(api = VERSION_CODES.M)
fun onReceivedError(
    view: WebView!,
    request: WebResourceRequest!,
    error: WebResourceError!
): Unit

onReceivedError

fun onReceivedError(
    view: WebView!,
    errorCode: Int,
    description: String!,
    failingUrl: String!
): Unit

onReceivedHttpAuthRequest

fun onReceivedHttpAuthRequest(
    view: WebView!,
    handler: HttpAuthHandler!,
    host: String!,
    realm: String!
): Unit

onReceivedHttpError

@RequiresApi(api = VERSION_CODES.M)
fun onReceivedHttpError(
    view: WebView!,
    request: WebResourceRequest!,
    errorResponse: WebResourceResponse!
): Unit

onReceivedLoginRequest

fun onReceivedLoginRequest(
    view: WebView!,
    realm: String!,
    account: String?,
    args: String!
): Unit

onReceivedSslError

fun onReceivedSslError(
    view: WebView!,
    handler: SslErrorHandler!,
    error: SslError!
): Unit

onRenderProcessGone

@RequiresApi(api = VERSION_CODES.O)
fun onRenderProcessGone(view: WebView!, detail: RenderProcessGoneDetail!): Boolean

onSafeBrowsingHit

@RequiresApi(api = VERSION_CODES.O_MR1)
fun onSafeBrowsingHit(
    view: WebView!,
    request: WebResourceRequest!,
    threatType: Int,
    callback: SafeBrowsingResponse!
): Unit

onScaleChanged

fun onScaleChanged(view: WebView!, oldScale: Float, newScale: Float): Unit

onTooManyRedirects

fun onTooManyRedirects(view: WebView!, cancelMsg: Message!, continueMsg: Message!): Unit

onUnhandledKeyEvent

fun onUnhandledKeyEvent(view: WebView!, event: KeyEvent!): Unit

setDelegateWebViewClient

fun setDelegateWebViewClient(delegate: WebViewClient?): Unit

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient.

shouldInterceptRequest

fun shouldInterceptRequest(view: WebView!, request: WebResourceRequest!): WebResourceResponse?

shouldInterceptRequest

fun shouldInterceptRequest(view: WebView!, url: String!): WebResourceResponse?

shouldOverrideKeyEvent

fun shouldOverrideKeyEvent(view: WebView!, event: KeyEvent!): Boolean

shouldOverrideUrlLoading

@RequiresApi(api = VERSION_CODES.N)
fun shouldOverrideUrlLoading(view: WebView!, request: WebResourceRequest!): Boolean

shouldOverrideUrlLoading

fun shouldOverrideUrlLoading(view: WebView!, url: String!): Boolean

Protected functions

getDelegate

protected fun getDelegate(): WebViewClient!