Webview Android Studio giving error to open mailto email links:

Asked

Viewed 955 times

0

I created an application using the WebView in Android Studio.

On my website where the WebView opens has email links that when clicking should open the default email application of the mobile. Only this does not happen and gives an error message:

Web page not available mailto:email address net::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");
    }
}

1 answer

0

It turns out that 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 on Manifest.xml:

<application
    ....
    android:usesCleartextTraffic="true"
    ....>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.