的WebView在Android的触发标准的浏览器 [英] WebView in Android fires standard browser

查看:93
本文介绍了的WebView在Android的触发标准的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经显示的网站创建于Android的一个活动。我用这个code:

I have created an Activity in Android for displaying websites. I used this code:

private WebView mWebview; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mWebview = new WebView(this);
    mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
    mWebview.loadUrl("http://blablabla");
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    setContentView(mWebview);

但是,当我使用它,例如www.bild.de,或它的移动版本wap.bild.de,它触发标准的浏览器,并从我的应用程序失控。同样的,如果我点击来自网站的链接。我不希望出现这种情况。我究竟做错了什么?谢谢你。

But when I use it with for example www.bild.de, or its mobile version wap.bild.de, it fires the standard browser and gets out from my app. The same if I tap a link from that website. I don't want that. What am I doing wrong? Thanks.

推荐答案

我只是跑你code。在我的手机上测试项目,似乎加载的第一页时正常工作。它装载wap.bild.de而不首次出现任何问题。

I just ran your code in a test project on my phone and it seems to work perfectly when loading the first page. It loaded wap.bild.de without any problems for the first time.

我做到了,但经验的默认浏览器,当我点击一个链接推出了同样的问题。为了解决这个问题,只需加上下面几行:

I did, however, experience the same problem that the default browser is launched when I tap on a link. To fix that, just add the following lines:

mWebview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url); // open link in the same web view.
            return true;
        }
    });

这篇关于的WebView在Android的触发标准的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆