0

I am following this tutorial. I am making an android app for one of my domains, it is a very basic viewer that shows the homepage, users can navigate to other pages staying within the app (instead of the popup asking them witch browser to use) but, I also have telephone numbers in the site as links, for example in this .tel page you can hover the mouse over and see the calto:xxxxx when I click on the phone in a browser it brings me the dial as I wish. When I click on it on my webview app it also works by bringing up the dial app.

But after implementing the following code in order to open all the pages and links inside the app, it does not work. It gives me a message inside the app because I can't open it

// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());

So I used this to make other requested domains (I would expect the phone numbers as well) open in another app, browser, (expecting the dial app as well) and it works for other sites but when I click on the phone number it only gives me this error and force closes the app

public class MyAppWebViewClient extends WebViewClient {
        
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if(Uri.parse(url).getHost().endsWith("html5rocks.com")) {
                return false;
            }
             
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        }
    }

The error

02-24 18:56:20.065  15423-15423/com.clicnet.bandeirantestel A/chromium﹕ [FATAL:jni_android.cc(271)] Check failed: false.
02-24 18:56:20.075  15423-15423/com.clicnet.bandeirantestel A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 15423 (bandeirantestel)
I tried to run it on lollipop and ics but the results are the same

Any help appreciated Thanks

ilgaar
  • 804
  • 1
  • 12
  • 31
rzfzr
  • 43
  • 1
  • 7

1 Answers1

0

I solved it using this

public boolean shouldOverrideUrlLoading(WebView view, String url)
       {Uri query_string=Uri.parse(url);
        String query_scheme=query_string.getScheme();
        String query_host=query_string.getHost();
        if ((query_scheme.equalsIgnoreCase("https") || query_scheme.equalsIgnoreCase("http"))
            && query_host!=null // && query_host.equalsIgnoreCase(Uri.parse(URL_SERVER).getHost())
            && query_string.getQueryParameter("new_window")==null
           )
           {return false;//handle the load by webview
           }
        try
           {Intent intent=new Intent(Intent.ACTION_VIEW, query_string);
            String[] body=url.split("\\?body=");
            if (query_scheme.equalsIgnoreCase("sms") && body.length>1)
               {intent=new Intent(Intent.ACTION_VIEW, Uri.parse(body[0]));
                intent.putExtra("sms_body", URLDecoder.decode(body[1]));
               }
            view.getContext().startActivity(intent);//handle the load by os
           }
        catch (Exception e) {}
        return true;
       }

It's an edited version of the first solution here (I had tried before opening this question) and notice how I commented out the part where it would exclude my homepage, that way it will open all pages in the WebView

Community
  • 1
  • 1
rzfzr
  • 43
  • 1
  • 7