【发布时间】:2021-10-01 12:21:43
【问题描述】:
如何阻止广告/弹出窗口/域
你好,我正在制作一个简单的 webview,我希望在这个 webview 中我可以限制我的用户可以访问哪些域,例如,我希望只访问 google.com 和 youtube.com,如何我这样做?
这是阻止弹出窗口和广告的最佳方式吗?
public class MainActivity extends AppCompatActivity {
WebView wv;
public void onBackPressed(){
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webView);
//Enable Javascript
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusableInTouchMode(true);
// set Render Priority to high
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
// Load url
wv.loadUrl("https://www.google.com/");
wv.setWebViewClient(new myWebViewClient());
}
String currentUrl;
private class myWebViewClient extends WebViewClient{
@Override
public void onLoadResource(WebView view, String url) {
Log.e("Resource ",url);
}
}
}
【问题讨论】:
标签: android android-studio webview popup ads