H5AdsWebViewClient

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


Một WebViewClient chặn và xử lý các yêu cầu quảng cáo H5. Để sử dụng tính năng này, hãy đặt tính năng này làm ứng dụng khách của WebView chứa các ứng dụng web sẽ đưa ra yêu cầu quảng cáo H5.

LƯU Ý QUAN TRỌNG: Bạn không thể dùng WebViewClient này cho nhiều WebView. Mọi WebView mới hỗ trợ quảng cáo H5 đều phải sử dụng một H5AdsWebViewClient mới.

Mã ví dụ:

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

Tóm tắt

Hàm khởi tạo công khai

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

Hàm khởi tạo cho H5AdsWebViewClient.

Hàm công khai

Unit

Huỷ tất cả quảng cáo do quảng cáo H5 quản lý.

WebViewClient?

Lấy đại biểu WebViewClient.

Unit

Đặt một WebViewClient để uỷ quyền các phương thức không được H5AdsWebViewClient xử lý.

Hàm được bảo vệ

WebViewClient!

Hàm kế thừa

Từ 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

Hàm này không còn được dùng nữa.

Unit
WebResourceResponse!
Boolean
Boolean

Hàm khởi tạo công khai

H5AdsWebViewClient

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

Hàm khởi tạo cho H5AdsWebViewClient.

Thông số
context: Context!

Ngữ cảnh hoạt động hoặc ứng dụng.

webView: WebView!

WebView sẽ được liên kết với H5AdsWebViewClient này. Bạn phải bật JavaScript trên WebView.

Hàm công khai

clearAdObjects

fun clearAdObjects(): Unit

Huỷ tất cả quảng cáo do quảng cáo H5 quản lý.

Lưu ý: Phương thức này không ảnh hưởng đến bất kỳ quảng cáo nào do API AdMob không phải H5 tạo, chẳng hạn như com.google.android.gms.ads.interstitial.InterstitialAd và com.google.android.gms.ads.rewarded.RewardedAd.

getDelegateWebViewClient

fun getDelegateWebViewClient(): WebViewClient?

Lấy đại biểu WebViewClient.

setDelegateWebViewClient

fun setDelegateWebViewClient(delegate: WebViewClient?): Unit

Đặt một WebViewClient để uỷ quyền các phương thức không được H5AdsWebViewClient xử lý.

Hàm được bảo vệ

getDelegate

protected fun getDelegate(): WebViewClient!