H5AdsWebViewClient

public final class H5AdsWebViewClient extends 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 methods

final void

Destroys all ads being managed by H5 ads.

void
doUpdateVisitedHistory(WebView view, String url, boolean isReload)
final WebViewClient

Gets the delegate WebViewClient.

void
onFormResubmission(WebView view, Message dontResend, Message resend)
void
void
void
void
onPageStarted(WebView view, String url, Bitmap favicon)
void
void
onReceivedError(
    WebView view,
    WebResourceRequest request,
    WebResourceError error
)
void
onReceivedHttpAuthRequest(
    WebView view,
    HttpAuthHandler handler,
    String host,
    String realm
)
void
onReceivedHttpError(
    WebView view,
    WebResourceRequest request,
    WebResourceResponse errorResponse
)
void
onReceivedLoginRequest(
    WebView view,
    String realm,
    String account,
    String args
)
void
onReceivedSslError(
    WebView view,
    SslErrorHandler handler,
    SslError error
)
boolean
void
@RequiresApi(api = 27)
onSafeBrowsingHit(
    WebView view,
    WebResourceRequest request,
    int threatType,
    SafeBrowsingResponse callback
)
void
onScaleChanged(WebView view, float oldScale, float newScale)
void
final void

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

WebResourceResponse
boolean
boolean

Inherited methods

From android.webkit.WebViewClient
void
onReceivedError(
    @NonNull WebView p0,
    int p1,
    @NonNull String p2,
    @NonNull String p3
)

This method is deprecated. Deprecated in Java

void
onTooManyRedirects(
    @NonNull WebView p0,
    @NonNull Message p1,
    @NonNull Message p2
)

This method is deprecated. Deprecated in Java

@Nullable WebResourceResponse

This method is deprecated. Deprecated in Java

boolean

This method is deprecated. Deprecated in Java

Public constructors

H5AdsWebViewClient

public H5AdsWebViewClient(@NonNull WebView webView)

Constructs a H5AdsWebViewClient.

Parameters
@NonNull WebView webView

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

Public methods

clearAdObjects

public final void clearAdObjects()

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

public void doUpdateVisitedHistory(WebView view, String url, boolean isReload)

getDelegateWebViewClient

public final WebViewClient getDelegateWebViewClient()

Gets the delegate WebViewClient.

onFormResubmission

public void onFormResubmission(WebView view, Message dontResend, Message resend)

onLoadResource

public void onLoadResource(@NonNull WebView view, String url)

onPageCommitVisible

public void onPageCommitVisible(WebView view, String url)

onPageFinished

public void onPageFinished(WebView view, String url)

onPageStarted

public void onPageStarted(WebView view, String url, Bitmap favicon)

onReceivedClientCertRequest

public void onReceivedClientCertRequest(WebView view, ClientCertRequest request)

onReceivedError

public void onReceivedError(
    WebView view,
    WebResourceRequest request,
    WebResourceError error
)

onReceivedHttpAuthRequest

public void onReceivedHttpAuthRequest(
    WebView view,
    HttpAuthHandler handler,
    String host,
    String realm
)

onReceivedHttpError

public void onReceivedHttpError(
    WebView view,
    WebResourceRequest request,
    WebResourceResponse errorResponse
)

onReceivedLoginRequest

public void onReceivedLoginRequest(
    WebView view,
    String realm,
    String account,
    String args
)

onReceivedSslError

public void onReceivedSslError(
    WebView view,
    SslErrorHandler handler,
    SslError error
)

onRenderProcessGone

@RequiresApi(api = 26)
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail)

onSafeBrowsingHit

@RequiresApi(api = 27)
public void onSafeBrowsingHit(
    WebView view,
    WebResourceRequest request,
    int threatType,
    SafeBrowsingResponse callback
)

onScaleChanged

public void onScaleChanged(WebView view, float oldScale, float newScale)

onUnhandledKeyEvent

public void onUnhandledKeyEvent(WebView view, KeyEvent event)

setDelegateWebViewClient

public final void setDelegateWebViewClient(WebViewClient delegate)

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

shouldInterceptRequest

public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)

shouldOverrideKeyEvent

public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event)

shouldOverrideUrlLoading

public boolean shouldOverrideUrlLoading(
    WebView view,
    @NonNull WebResourceRequest request
)