javascript - WebView Android not satisfying S.browser_fallback_url - Stack Overflow

admin2025-04-26  2

I am trying to implement an app that uses webview, inside the html loaded on clicking a button the app a intent url of the form intent://<data>#Intent;scheme=<scheme-name>;action=android.intent.action.VIEW;S.browser_fallback_url=<url>;end is opened, If the intent can be handled by an app downloaded then it opens but if the app is not downloaded or the scheme is misspelt then I get net::ERR_UNKNOWN_URL_SCHEME it does not go to the fallback_url provided.

If I use the same intent url in the browser directly then the fallback url is respected

I have tried creating a webViewClient

       myWebView.setWebViewClient(new WebViewClient() {
           @Override
           public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
               if(URLUtil.isNetworkUrl(request.getUrl().toString())) {
                   return false;
               }

               Intent intent;
               try {
                   intent = Intent.parseUri(request.getUrl().toString(), Intent.URI_INTENT_SCHEME);
               }
               catch (URISyntaxException e){
                   return false;
               }

               try{
                   view.getContext().startActivity(intent);
               }
               catch (ActivityNotFoundException e){
                   String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                   if(fallbackUrl != null){
                       view.loadUrl(fallbackUrl);
                   }
               }

               return true;
           }
       });

which works but according to my understanding as given in S.browser_fallback_url should work without the use of a webClient and is already part of webview

What needs to be changed to make it work?

Thanks in advance

转载请注明原文地址:http://anycun.com/QandA/1745598344a90984.html