H5AdsWebViewClient

@RequiresApi(api = VERSION_CODES.LOLLIPOP)
class H5AdsWebViewClient : WebViewClient


WebViewClient,可攔截及處理 H5 廣告請求。如要使用這項功能,請將此項設為 WebView 的用戶端,其中包含會發出 H5 廣告要求的網頁應用程式。

重要事項:這個 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 的建構函式。

公開函式

Unit

銷毀 H5 廣告管理的所有廣告。

WebViewClient?

取得委派 WebViewClient。

Unit

設定 WebViewClient,將 H5AdsWebViewClient 未處理的方法委派給該物件。

受保護的函式

WebViewClient!

繼承函式

來自 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

這個函式已淘汰。

Unit
WebResourceResponse!
Boolean
Boolean

公用建構函式

H5AdsWebViewClient

H5AdsWebViewClient(context: Context!, webView: WebView!)

H5AdsWebViewClient 的建構函式。

參數
context: Context!

活動或應用程式情境。

webView: WebView!

與這個 H5AdsWebViewClient 相關聯的 WebView。WebView 必須啟用 JavaScript。

公開函式

clearAdObjects

fun clearAdObjects(): Unit

系統會銷毀 H5 廣告管理的所有廣告。

注意:這個方法不會影響非 H5 AdMob API (例如 com.google.android.gms.ads.interstitial.InterstitialAd 和 com.google.android.gms.ads.rewarded.RewardedAd) 建立的任何廣告。

getDelegateWebViewClient

fun getDelegateWebViewClient(): WebViewClient?

取得委派 WebViewClient。

setDelegateWebViewClient

fun setDelegateWebViewClient(delegate: WebViewClient?): Unit

設定 WebViewClient,將 H5AdsWebViewClient 未處理的方法委派給該物件。

受保護的函式

getDelegate

protected fun getDelegate(): WebViewClient!