H5AdsWebViewClient

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:


fun onCreate(savedInstanceState: Bundle?) {
...

// JavaScript must be enabled.
val myWebView = findViewById(R.id.my_webview)
myWebView.settings.javascriptEnabled = true

val h5Client = H5AdsWebViewClient(this, myWebView)

// (Optional) Add existing WebViewClient as delegate
val myClient = ...
h5Client.setDelegateWebViewClient(myClient)

webView.setWebViewClient(h5Client);
}

Summary

Public constructors

Constructs a H5AdsWebViewClient.

Public functions

Unit

Destroys all ads being managed by H5 ads.

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

Gets the delegate WebViewClient.

open Unit
onFormResubmission(view: WebView?, dontResend: Message?, resend: Message?)
open Unit
onLoadResource(view: WebView, url: String?)
open Unit
open Unit
onPageFinished(view: WebView?, url: String?)
open Unit
onPageStarted(view: WebView?, url: String?, favicon: Bitmap?)
open Unit
open Unit
onReceivedError(
    view: WebView?,
    request: WebResourceRequest?,
    error: WebResourceError?
)
open Unit
onReceivedHttpAuthRequest(
    view: WebView?,
    handler: HttpAuthHandler?,
    host: String?,
    realm: String?
)
open Unit
onReceivedHttpError(
    view: WebView?,
    request: WebResourceRequest?,
    errorResponse: WebResourceResponse?
)
open Unit
onReceivedLoginRequest(
    view: WebView?,
    realm: String?,
    account: String?,
    args: String?
)
open Unit
onReceivedSslError(
    view: WebView?,
    handler: SslErrorHandler?,
    error: SslError?
)
open Boolean
open Unit
@RequiresApi(api = 27)
onSafeBrowsingHit(
    view: WebView?,
    request: WebResourceRequest?,
    threatType: Int,
    callback: SafeBrowsingResponse?
)
open Unit
onScaleChanged(view: WebView?, oldScale: Float, newScale: Float)
open Unit
Unit

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient, which are all methods except for onLoadResource and both versions of shouldOverrideUrlLoading.

open WebResourceResponse?
open Boolean
open Boolean

Inherited functions

From android.webkit.WebViewClient
open Unit
onReceivedError(p0: WebView, p1: Int, p2: String, p3: String)

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open WebResourceResponse?

This function is deprecated. Deprecated in Java

open Boolean

This function is deprecated. Deprecated in Java

Public constructors

H5AdsWebViewClient

H5AdsWebViewClient(webView: WebView)

Constructs a H5AdsWebViewClient.

Parameters
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.libraries.ads.mobile.sdk.interstitial.InterstitialAd and com.google.android.libraries.ads.mobile.sdk.rewarded.RewardedAd.

doUpdateVisitedHistory

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

getDelegateWebViewClient

fun getDelegateWebViewClient(): WebViewClient?

Gets the delegate WebViewClient.

onFormResubmission

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

onLoadResource

open fun onLoadResource(view: WebView, url: String?): Unit

onPageCommitVisible

open fun onPageCommitVisible(view: WebView?, url: String?): Unit

onPageFinished

open fun onPageFinished(view: WebView?, url: String?): Unit

onPageStarted

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

onReceivedClientCertRequest

open fun onReceivedClientCertRequest(view: WebView?, request: ClientCertRequest?): Unit

onReceivedError

open fun onReceivedError(
    view: WebView?,
    request: WebResourceRequest?,
    error: WebResourceError?
): Unit

onReceivedHttpAuthRequest

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

onReceivedHttpError

open fun onReceivedHttpError(
    view: WebView?,
    request: WebResourceRequest?,
    errorResponse: WebResourceResponse?
): Unit

onReceivedLoginRequest

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

onReceivedSslError

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

onRenderProcessGone

@RequiresApi(api = 26)
open fun onRenderProcessGone(view: WebView?, detail: RenderProcessGoneDetail?): Boolean

onSafeBrowsingHit

@RequiresApi(api = 27)
open fun onSafeBrowsingHit(
    view: WebView?,
    request: WebResourceRequest?,
    threatType: Int,
    callback: SafeBrowsingResponse?
): Unit

onScaleChanged

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

onUnhandledKeyEvent

open fun onUnhandledKeyEvent(view: WebView?, event: KeyEvent?): Unit

setDelegateWebViewClient

fun setDelegateWebViewClient(delegate: WebViewClient?): Unit

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient, which are all methods except for onLoadResource and both versions of shouldOverrideUrlLoading.

shouldInterceptRequest

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

shouldOverrideKeyEvent

open fun shouldOverrideKeyEvent(view: WebView?, event: KeyEvent?): Boolean

shouldOverrideUrlLoading

open fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest): Boolean