0

I already make a java WebView for my website, this website in the footer the phone number and the email address when I click in it they told me (the webpage at tel could not be loaded because err_unknown_url_scheme), What should i do ?

MainActivity.Java

package xxx.xxxxxxx.xxxxxxxxx;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {

    private WebView webView;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try
        {
            Objects.requireNonNull(this.getSupportActionBar()).hide();
        }
        catch (NullPointerException ignored){}

        //find the view
        webView = findViewById(R.id.webview);
        // to load all the web page in app itself use this
        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl("https://www.ezyadvs.com");

        WebSettings webSettings =webView.getSettings();

        //if your website is using any javascript that needs to load some script then you need to enable javascript in android application
        webSettings.setJavaScriptEnabled(true);

    }

    @Override
    public void onBackPressed() {
        // if any previous webpage exist then onback pressed will take care of it

        if(webView.canGoBack())
        {
            webView.goBack();
        }else{

            //else it will exit the application
            super.onBackPressed();
        }

    }
}
Abra
  • 19,142
  • 7
  • 29
  • 41
AlaaEldin
  • 1
  • 1

1 Answers1

0

Here is my solution in .kt (kotlin) :

            this.webView.webViewClient = object : WebViewClient() {
                override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {

                    //add condition startsWith("tel:") or startsWith("mailto:")
                    if (url!!.startsWith("whatsapp:")) {
                        val intent = Intent(Intent.ACTION_VIEW)
                        intent.data = Uri.parse(url)
                        startActivity(intent)
                        return true
                    } 
                    return false
                }
            }