支持Android中的WebView其他协议协议、Android、WebView

2023-09-12 09:04:10 作者:书中传奇

我已经创建了一个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.

 
精彩推荐
图片推荐