我正在开发一个移动应用程序。在一些选项上,我将用户重定向到不同的网站,如http://m.moneycontrol.com/,http://www.redbus.com/等。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.loadUrl("http://www.m.moneycontrol.com/");
// mainWebView.setScrollBarStyle(MainActivity.this.SCROLLBARS_INSIDE_OVERLAY);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading (WebView view, String url){
//True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.
return true;
}
});
}
private class MyCustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}当我在一些手机上测试这个应用程序时。在2-3部手机上,webview开始重定向到不同的网站,并开始打开联属广告来安装杀毒软件等。
请建议我阻止这些广告的解决方案。
发布于 2015-09-17 23:34:05
将WebView的用户代理字符串更改为IE或桌面Firefox的字符串。网站将显示网站的常规版本,希望广告不会出现在那里。
webview.getSettings().setUserAgentString(
"Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20100101 Firefox/12");发布于 2015-09-16 02:10:17
一般的建议是,不要在你的应用程序的WebView中打开任何你无法控制的网站。不要这样做,只需启动系统浏览器:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.m.moneycontrol.com/")));https://stackoverflow.com/questions/32589499
复制相似问题