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:

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);
 }
 

Inherited Constant Summary

Public Constructor Summary

H5AdsWebViewClient(Context context, WebView webView)
Constructor for H5AdsWebViewClient.

Public Method Summary

void
clearAdObjects()
Destroys all ads being managed by H5 ads.
void
doUpdateVisitedHistory(WebView view, String url, boolean isReload)
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, int errorCode, String description, String failingUrl)
void
void
void
void
onReceivedLoginRequest(WebView view, String realm, String account, String args)
void
boolean
void
onSafeBrowsingHit(WebView view, WebResourceRequest request, int threatType, SafeBrowsingResponse callback)
void
onScaleChanged(WebView view, float oldScale, float newScale)
void
onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg)
void
void
setDelegateWebViewClient(WebViewClient delegate)
Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient.
WebResourceResponse
WebResourceResponse
boolean
boolean
boolean

Protected Method Summary

WebViewClient

Inherited Method Summary

Public Constructors

public H5AdsWebViewClient (Context context, WebView webView)

Constructor for H5AdsWebViewClient.

Parameters
context An activity or application context.
webView The WebView that will be associated with this H5AdsWebViewClient. JavaScript must be enabled on the WebView.

Public Methods

public 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 InterstitialAd and RewardedAd.

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

public WebViewClient getDelegateWebViewClient ()

Gets the delegate WebViewClient.

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

public void onLoadResource (WebView view, String url)

public void onPageCommitVisible (WebView view, String url)

public void onPageFinished (WebView view, String url)

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

public void onReceivedClientCertRequest (WebView view, ClientCertRequest request)

public void onReceivedError (WebView view, int errorCode, String description, String failingUrl)

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

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

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

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

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

public boolean onRenderProcessGone (WebView view, RenderProcessGoneDetail detail)

public void onSafeBrowsingHit (WebView view, WebResourceRequest request, int threatType, SafeBrowsingResponse callback)

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

public void onTooManyRedirects (WebView view, Message cancelMsg, Message continueMsg)

public void onUnhandledKeyEvent (WebView view, KeyEvent event)

public void setDelegateWebViewClient (WebViewClient delegate)

Sets a WebViewClient to delegate methods not handled by H5AdsWebViewClient.

public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)

public WebResourceResponse shouldInterceptRequest (WebView view, String url)

public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event)

public boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request)

public boolean shouldOverrideUrlLoading (WebView view, String url)

Protected Methods

protected WebViewClient getDelegate ()