H5AdsWebViewClient

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


Um WebViewClient que intercepta e processa as solicitações de anúncios H5. Para usar isso, defina como o cliente do WebView que contém os apps da Web que vão fazer solicitações de anúncios H5.

IMPORTANTE: esse WebViewClient não pode ser usado para vários WebViews. Cada nova WebView que oferece suporte a anúncios H5 precisa usar uma nova H5AdsWebViewClient.

Exemplo de código:

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

Resumo

Construtores públicos

H5AdsWebViewClient(Context context, WebView webView)

Construtor para H5AdsWebViewClient.

Métodos públicos

void

Destrói todos os anúncios gerenciados por anúncios H5.

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

Recebe o delegado WebViewClient.

void
onFormResubmission(WebView view, Message dontResend, Message resend)
void
void
@RequiresApi(api = VERSION_CODES.M)
onPageCommitVisible(WebView view, String url)
void
void
onPageStarted(WebView view, String url, Bitmap favicon)
void
void
@RequiresApi(api = VERSION_CODES.M)
onReceivedError(
    WebView view,
    WebResourceRequest request,
    WebResourceError error
)
void
onReceivedError(
    WebView view,
    int errorCode,
    String description,
    String failingUrl
)

Esse método foi descontinuado.

void
onReceivedHttpAuthRequest(
    WebView view,
    HttpAuthHandler handler,
    String host,
    String realm
)
void
@RequiresApi(api = VERSION_CODES.M)
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)

Esse método foi descontinuado.

void
void

Define um WebViewClient para delegar métodos não processados por H5AdsWebViewClient.

@Nullable WebResourceResponse
@Nullable WebResourceResponse

Esse método foi descontinuado.

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

Esse método foi descontinuado.

Métodos protegidos

WebViewClient

Constantes herdadas

De 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

Métodos herdados

De android.webkit.WebViewClient
void
doUpdateVisitedHistory(WebView p, String p1, boolean p2)
void
void
void
void
void
void
void
void
onReceivedHttpAuthRequest(
    WebView p,
    HttpAuthHandler p1,
    String p2,
    String p3
)
void
void
void
boolean
void
onSafeBrowsingHit(
    WebView p,
    WebResourceRequest p1,
    int p2,
    SafeBrowsingResponse p3
)
void
onScaleChanged(WebView p, float p1, float p2)
void

Esse método foi descontinuado.

void
WebResourceResponse
boolean
boolean

Construtores públicos

H5AdsWebViewClient

public H5AdsWebViewClient(Context context, WebView webView)

Construtor para H5AdsWebViewClient.

Parâmetros
Context context

Uma atividade ou um contexto do aplicativo.

WebView webView

O WebView que será associado a esse H5AdsWebViewClient. O JavaScript precisa estar ativado na WebView.

Métodos públicos

clearAdObjects

public void clearAdObjects()

Destrói todos os anúncios gerenciados por anúncios H5.

Observação: esse método não afeta os anúncios criados pela API da AdMob que não é H5, como e .

doUpdateVisitedHistory

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

getDelegateWebViewClient

public @Nullable WebViewClient getDelegateWebViewClient()

Recebe o delegado WebViewClient.

onFormResubmission

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

onLoadResource

public void onLoadResource(WebView view, String url)

onPageCommitVisible

@RequiresApi(api = VERSION_CODES.M)
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

@RequiresApi(api = VERSION_CODES.M)
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

@RequiresApi(api = VERSION_CODES.M)
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)

Define um WebViewClient para delegar métodos não processados por 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)

Métodos protegidos

getDelegate

protected WebViewClient getDelegate()