H5AdsWebViewClient

@RequiresApi(api = VERSION_CODES.LOLLIPOP)
public final class H5AdsWebViewClient extends WebViewClient


一种用于拦截和处理 H5 广告请求的 WebViewClient。若要使用此功能,请将其设置为 WebView 的客户端,该 WebView 包含将发出 H5 广告请求的 Web 应用。

重要提示:此 WebViewClient 不能用于多个 WebView。每个将支持 H5 广告的新 WebView 都必须使用新的 H5AdsWebViewClient

示例代码:

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

摘要

公共构造函数

H5AdsWebViewClient(Context context, WebView webView)

H5AdsWebViewClient 的构造函数。

公共方法

void

销毁 H5 广告管理的所有广告。

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

获取委托 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
onReceivedError(
    WebView view,
    int errorCode,
    String description,
    String failingUrl
)

此方法已弃用。

void
onReceivedHttpAuthRequest(
    WebView view,
    HttpAuthHandler handler,
    String host,
    String realm
)
void
onReceivedHttpError(
    WebView view,
    WebResourceRequest request,
    WebResourceResponse errorResponse
)
void
onReceivedLoginRequest(
    WebView view,
    String realm,
    @Nullable String account,
    String args
)
void
onReceivedSslError(
    WebView view,
    SslErrorHandler handler,
    SslError error
)
boolean
@RequiresApi(api = VERSION_CODES.O)
onRenderProcessGone(WebView view, RenderProcessGoneDetail detail)
void
@RequiresApi(api = VERSION_CODES.O_MR1)
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

设置 WebViewClient 以委托 H5AdsWebViewClient 未处理的方法。

@Nullable WebResourceResponse
@Nullable WebResourceResponse

此方法已弃用。

boolean
boolean
@RequiresApi(api = VERSION_CODES.N)
shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
boolean

此方法已弃用。

受保护的方法

WebViewClient

继承的常量

来自 android.webkit.WebViewClient
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

继承的方法

来自 android.webkit.WebViewClient

公共构造函数

H5AdsWebViewClient

public H5AdsWebViewClient(Context context, WebView webView)

H5AdsWebViewClient 的构造函数。

参数
Context context

activity 或应用上下文。

WebView webView

将与此 H5AdsWebViewClient 关联的 WebView。必须在 WebView 上启用 JavaScript。

公共方法

clearAdObjects

public void clearAdObjects()

销毁 H5 广告管理的所有广告。

注意:此方法对非 H5 AdMob API(例如 和 )创建的任何广告均无效。

doUpdateVisitedHistory

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

getDelegateWebViewClient

public @Nullable WebViewClient getDelegateWebViewClient()

获取委托 WebViewClient

onFormResubmission

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

onLoadResource

public void onLoadResource(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
)

onReceivedError

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

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,
    @Nullable String account,
    String args
)

onReceivedSslError

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

onRenderProcessGone

@RequiresApi(api = VERSION_CODES.O)
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail)

onSafeBrowsingHit

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

onScaleChanged

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

onTooManyRedirects

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

onUnhandledKeyEvent

public void onUnhandledKeyEvent(WebView view, KeyEvent event)

setDelegateWebViewClient

public void setDelegateWebViewClient(@Nullable WebViewClient delegate)

设置 WebViewClient 以委托 H5AdsWebViewClient 未处理的方法。

shouldInterceptRequest

public @Nullable WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)

shouldInterceptRequest

public @Nullable WebResourceResponse shouldInterceptRequest(WebView view, String url)

shouldOverrideKeyEvent

public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event)

shouldOverrideUrlLoading

@RequiresApi(api = VERSION_CODES.N)
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)

shouldOverrideUrlLoading

public boolean shouldOverrideUrlLoading(WebView view, String url)

受保护的方法

getDelegate

protected WebViewClient getDelegate()