I am using webview in my android app.
I have 3 buttons 1 for a link to a website where you can call by number and email.
First, a button call to the website http://www.somelink.com .
But my tel: link did not work. So I included some code that made me work with the body:
The problem is that he launched my website or http button:
The html button does nothing when you click on it.
package de.sonae.novolam; import android.annotation.SuppressLint; import android.app.Fragment; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.webkit.WebViewClient; @SuppressLint("SetJavaScriptEnabled") public class DFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mainView = (View) inflater.inflate(R.layout.dfragment, container, false); WebView webView = (WebView) mainView.findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView wv, String url) { if (url.startsWith("tel:")) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); startActivity(intent); } return true; } }); webView.loadUrl("file:///android_asset/contact.html"); return mainView; } public boolean shouldOverrideUrlLoading(WebView webView, String url) { if( url.startsWith("http:") || url.startsWith("https:") ) { webView.loadUrl(url); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity( intent ); } else if (url.startsWith("mailto:")) { }
source share