支持Android中的WebView其他协议 [英] Support for other protocols in Android webview

查看:575
本文介绍了支持Android中的WebView其他协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Web视图应用程序,这显示市场的功能页面://链接,但在点击他们,我得到了404的屏幕以及不支持该协议的错误。我试图寻找通过的文件,但未能找到有关的事。任何帮助是非常AP preciated。

I've created a web view app, the page that is displayed features market:// links but upon clicking them I get the 404 screen along with the error that the protocol is not supported. I've tried looking through documentation but was unable to find anything relating to this. Any help is much appreciated.

推荐答案

对我来说,JavaScript的事情是不是一个解决方案,因为该HTML不是我的控制之下。所以,如果你需要从应用端控制这个,然后有一个相对简单的解决方案:从 WebViewClient 导出并利用注入实施 WebView.setWebViewClient ()。所有你需要在你的 WebViewClient 实施覆盖是 shouldOverrideUrlLoading 方法,如下图所示:

For me the JavaScript thing wasn't a solution as the HTML is not under my control. So if you need to control this from the application side, then there is a relative simple solution: Derive from WebViewClientand inject the implementation using WebView.setWebViewClient(). All you need to override in your WebViewClientimplementation is the shouldOverrideUrlLoading method as shown here:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url != null && url.startsWith("market://")) {
        view.getContext().startActivity(
            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        return true;
    } else {
        return false;
    }
}

对于我这个工作得很好。

For me this works fine.

这篇关于支持Android中的WebView其他协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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