我即将为我的板球团队推出一款应用,我们可以在其中查看或匹配视频...但是,在网页视图中有一些广告,如果点击广告,则会加载到同一网页视图中所以视频丢失了。如何实现在Android浏览器而不是app webview中打开广告的代码?
.java文件
WebView displayVideo = findViewById(R.id.webView); displayVideo.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
setTitle("Loading...");
}
@Override
public void onPageFinished(WebView view, String url){
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
setTitle(view.getTitle());
view.loadUrl("javascript:onPageFinished();");
}
});
WebSettings webSettings = displayVideo.getSettings();
webSettings.setJavaScriptEnabled(true);
displayVideo.loadData(frameVideo, "text/html", "utf-8");
webSettings.setMediaPlaybackRequiresUserGesture(false);
}
答案 0 :(得分:0)
您可以通过
拦截网址加载 @Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri url = request.getUrl();
// checking your url pattern
return super.shouldOverrideUrlLoading(view, request);
}
如果网址是广告网址。您可以通过Intent打开浏览器 - > Sending an Intent to browser to open specific URL