N
N
Nikolai2020-05-03 17:42:09
Java
Nikolai, 2020-05-03 17:42:09

Why does WebView and tel: link work crookedly?

Hello. There is an application on the minimum on webview. I assembled the frame on skethware, and then finished it on android studio. Piece of code:

webview2.setWebViewClient(new WebViewClient() {
      @Override
      public void onPageStarted(WebView _param1, String _param2, Bitmap _param3) {
        if ((_param2.startsWith("https://wa.me/")) || (_param2.startsWith("https://vk.com/")) || (_param2.startsWith("https://instagram.com")) || (_param2.startsWith("https://www.facebook.com/")) || (_param2.startsWith("mailto:")) || (_param2.startsWith("viber://")) || (_param2.startsWith("https://www.gismeteo")) || (_param2.startsWith("https://t.me")) || (_param2.startsWith("https://twitter.com/")) || (_param2.startsWith("https://connect.ok.ru/")) || (_param2.startsWith("https://telegram.me/")) || (_param2.startsWith("https://api."))){
          webview2.stopLoading();
          intent1.setData(Uri.parse(_param2));
          intent1.setAction(Intent.ACTION_VIEW);
          webview2.goBack();
          startActivity(intent1);
        }
        _fab.hide();
        t = new TimerTask() {
          @Override
          public void run() {
            runOnUiThread(new Runnable() {
              @Override
              public void run() {
                webview2.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
                                webview2.getSettings().setJavaScriptEnabled(true);
                                webview2.getSettings().setSupportZoom(false);
              }
            });
          }
        };
        
        if (_param2.startsWith("file:///android_asset/www/index.html")) {
          webview2.clearHistory();
        }
        if (_param2.startsWith("tel:")) {
          webview2.stopLoading();
          intent1.setData(Uri.parse(_param2));
          webview2.goBack();
          intent1.setAction(Intent.ACTION_DIAL);
          webview2.loadUrl(String.valueOf(getCacheDir()));
          startActivity(intent1);
        }

And here I have a problem with links, namely with the speed of their processing - I click, for example, on t.me/my_acc, and the application just freezes for a few seconds (apparently it does something of its own) and after a while performs the desired action. Same with the rest of the links.
The exception is tel:, which immediately calls the intent dial, but at the same time, on the page on which the number is indicated, an invisible film appears, as it were, preventing interaction with the page. After that, the page can be interacted with only after pressing the hardware back button, and then not always (throws it to the previous page). I myself am quite far from Java, and I have neither the time nor the opportunity to study from scratch. Please tell me how to bring these reactions to mind.
PS I googled several options, but none of them came up. Most likely my cant, due to not knowing the language. For example this one:
private class CustomWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String url) {
            if(url.startsWith("tel:")) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse(url));
                startActivity(intent);
                return true;
            }
            return false;
        }
    }


PS2. How to make page loading progress bar like chrome? I mean the blue bar at the top, which shows the status and progress of the page loading, without interfering with anything or anyone

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question