Support for other protocols in Android webview

前端 未结 7 2178
囚心锁ツ
囚心锁ツ 2020-11-29 04:08

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 s

7条回答
  •  情书的邮戳
    2020-11-29 04:43

    For the links to work you have to have the market app installed on your device/emulator. Also your app need to request a permission to access network.

    UPD: as a workaround you can call java code from within the webview, for example if you generate links like this:

    ..
    

    Define a javascript function named go():

    
    

    You then can pass in a handler object into the WebView:

    webview.addJavascriptInterface(new Handler() {
            @Override
            public void go(String marketUrl) {
                             //start market intent here
            }
        },  "handler");
    

    Handler interface can be defined as follows:

       public interface Handler{
    
        public void go(String url);
    
    }
    

提交回复
热议问题