WebView Android Studio giving error to open e-mail links mailto:

0

I created an application using WebView in Android Studio.

On my website where WebView opens has email links that when clicked should open the default email application on your phone. But this does not happen and gives an error message:

  

No webpage available mailto: net email address :: ERR_UNKNOWN_URL_SCHEME.

Source code of WebView :

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity
{

    private WebView miWebview;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        miWebview = findViewById(R.id.wv_main);
        miWebview.getSettings().setJavaScriptEnabled(true);
        miWebview.setWebViewClient(new WebViewClient());
        miWebview.loadUrl("http://cariocaempregos.com.br");
    }
}
    
asked by anonymous 27.10.2018 / 20:17

1 answer

0

The webview is making an internal request to open the email. Include the code below:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    miWebview = findViewById(R.id.wv_main);
    miWebview.getSettings().setJavaScriptEnabled(true);
    miWebview.setWebViewClient(new WebViewClient());
    miWebview.loadUrl("http://cariocaempregos.com.br");
    miWebview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("http:") || url.startsWith("https:")) {
                return false;
            }

            // Otherwise allow the OS to handle it
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        }
    });
 }

Another point, include the tag in Manifest.xml :

<application
    ....
    android:usesCleartextTraffic="true"
    ....>
    
29.10.2018 / 17:33