0

only whtatsaap work but not twitter or viber. Also when I click other links on my app it open in browser not in app. Also When I remove twitter or viber linking code then then it open in app, but as soon as I app twitter linking code it again open browser not in app and viber code is is not working at all please help Here is the code

Blockquote

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);


        webView.setWebViewClient(new WebViewClient(){

            @Override
            public boolean shouldOverrideUrlLoading(WebView wv, String url) {

                System.out.println("hERE IS VALUE OF WebView OBJECT "+ wv);
                System.out.println("hERE IS VALUE OF URL "+ url);
                try {

                 if (url.startsWith("tel:") || url.startsWith("whatsapp:")) {

                     System.out.println("URL SHOW MR whatsaap  ++++++++  " + url);
                     Intent intenti = new Intent(Intent.ACTION_VIEW);
                     intenti.setData(Uri.parse(url));
                     startActivity(intenti);
                     return false;
                 }
                    if (url.startsWith("telegram:")){
                    System.out.println("URL SHOW MR  TELEGRAM  ++++++++  " + url);
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return false;}

                    if (url.startsWith("viber:")){
                    System.out.println("URL SHOW ME  VIBER  ++++++++  " + url);
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);}
                }
                catch ( Exception e)
                {}
                return false;
            }

        } );

        webView.loadUrl("https://example.co.in/");
    }

Blockquote

rashmi
  • 1

2 Answers2

0

Try use ( webView.stopLoading() ) example

if (url.startsWith("tel:") || url.startsWith("whatsapp:")) {
                    System.out.println("URL SHOW MR whatsaap  ++++++++  " + url);
                    Intent intenti = new Intent(Intent.ACTION_VIEW);
                    intenti.setData(Uri.parse(url));
                    startActivity(intenti);
                    webView.stopLoading();
                    return false;
                }
  • But why? What is different from the code posted by the OP? – sanitizedUser Jul 10 '23 at 08:41
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 10 '23 at 08:41
  • You did everything right, but the code { return false } does not stop the browser from trying to load an invalid URL. – KiborgMaster Jul 11 '23 at 09:42
0

Best solution for me

        @Override
        public boolean shouldOverrideUrlLoading(WebView wv, WebResourceRequest request) {
            String url = request.getUrl().toString();
            
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);

            return true;
        }