title: Android- mailto link won't work
body: <p>I have read many Questions about this topic here at stackoverflow, also my solution come from here but it won't work. Also there is no error message.</p>
  
  <p>I have a webview in Android and a Homepage, there are some mailto links, when I try to open the mailto links from my webview in a mailclient, the webview always open the mail address like a normal webpage. </p>
  
  <p>Could someone look at my code and tell my what's wrong?</p>
  
  <p>Thank's for your help.</p>
  
  <p>Code:</p>
  
  <p><strong>Manifest file:</strong></p>
  
  <pre><code>1&lt;?xml version="1.0" encoding="utf-8"?&gt;
  2&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 package="com.example.TEST"
  4 android:versionCode="1"
  5 android:versionName="1.5" android:installLocation="auto"&gt;
  6
  7 &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  8 &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  9 &lt;uses-permission android:name="android.permission.ACCESS_GPS" /&gt;
  10  &lt;uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" /&gt;
  11  &lt;uses-permission android:name="android.permission.ACCESS_LOCATION" /&gt;
  12  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  13
  14 &lt;uses-sdk
  15 android:minSdkVersion="8"
  16 android:targetSdkVersion="17" /&gt;
  17
  18 &lt;application
  19 android:allowBackup="true"
  20 android:icon="@drawable/ic_launcher"
  21 android:label="@string/app_name"
  22 android:theme="@style/AppTheme" &gt;
  23 &lt;activity
  24 android:name="com.example.lauffinderpro.MainActivity"
  25 android:label="@string/app_name" &gt;
  26 &lt;intent-filter&gt;
  27 &lt;action android:name="android.intent.action.MAIN" /&gt;
  28
  29 &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
  30 &lt;/intent-filter&gt;
  31 &lt;/activity&gt;
  32 &lt;/application&gt;
  33
  34&lt;/manifest&gt;
  </code></pre>
  
  <p><strong>main.xml</strong></p>
  
  <pre><code>1&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2 xmlns:tools="http://schemas.android.com/tools"
  3 android:id="@+id/FrameLayout1"
  4 android:layout_width="match_parent"
  5 android:layout_height="match_parent"
  6 android:paddingBottom="@dimen/vertical"
  7 android:paddingLeft="@dimen/horizontal"
  8 android:paddingRight="@dimen/horizontal"
  9 android:paddingTop="@dimen/vertical"
  10 tools:context=".MainActivity" &gt;
  11
  12 &lt;LinearLayout
  13 android:layout_width="match_parent"
  14 android:layout_height="match_parent"
  15 android:orientation="vertical" &gt;
  16
  17 &lt;WebView
  18 android:id="@+id/webView1"
  19 android:layout_width="match_parent"
  20 android:layout_height="0dp"
  21 android:layout_weight="0.05" /&gt;
  22
  23 &lt;FrameLayout
  24 android:layout_width="match_parent"
  25 android:layout_height="wrap_content"
  26 android:layout_weight="0.00" &gt;
  27
  28 &lt;LinearLayout
  29 android:layout_width="match_parent"
  30 android:layout_height="wrap_content"
  31 android:baselineAligned="true" &gt;
  32
  33
  34 &lt;Button
  35 android:id="@+id/button1"
  36 android:layout_width="0dp"
  37 android:layout_weight="2"
  38 android:layout_height="match_parent"
  39 android:background="@drawable/upgradetest"
  40 android:onClick="button1click" /&gt;
  41
  42 &lt;Button
  43 android:id="@+id/button2"
  44 style="?android:attr/buttonStyleSmall"
  45 android:layout_width="0dp"
  46 android:layout_weight="2"
  47 android:layout_height="match_parent"
  48 android:background="@drawable/globaltest"
  49 android:onClick="button2click" /&gt;
  50
  51 &lt;Button
  52 android:id="@+id/button3"
  53 style="?android:attr/buttonStyleSmall"
  54 android:layout_width="0dp"
  55 android:layout_weight="2"
  56 android:layout_height="match_parent"
  57 android:background="@drawable/datetest"
  58 android:onClick="button3click" /&gt;
  59
  60 &lt;Button
  61 android:id="@+id/button5"
  62 style="?android:attr/buttonStyleSmall"
  63 android:layout_width="0dp"
  64 android:layout_weight="2"
  65 android:layout_height="match_parent"
  66 android:layout_gravity="right"
  67 android:background="@drawable/mehrtest"
  68 android:onClick="button5click" /&gt;
  69 &lt;/LinearLayout&gt;
  70
  71 &lt;/FrameLayout&gt;
  72
  73 &lt;/LinearLayout&gt;
  74
  75&lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>main.java</strong></p>
  
  <pre><code>1package com.example.lauffinderpro;
  2
  3import java.net.URISyntaxException;
  4
  5import android.net.MailTo;
  6import android.net.Uri;
  7import android.os.Bundle;
  8import android.annotation.SuppressLint;
  9import android.app.Activity;
  10import android.app.AlertDialog;
  11import android.content.Context;
  12import android.content.DialogInterface;
  13import android.content.Intent;
  14import android.util.Log;
  15import android.view.KeyEvent;
  16import android.view.Menu;
  17import android.view.View;
  18import android.view.View.OnClickListener;
  19import android.webkit.GeolocationPermissions;
  20import android.webkit.WebChromeClient;
  21import android.webkit.WebView;
  22import android.webkit.WebViewClient;
  23import android.widget.Button;
  24import android.widget.ImageButton;
  25
  26public class MainActivity extends Activity {
  27  
  28  
  29  protected void onCreate(Bundle savedInstanceState) {
  30  super.onCreate(savedInstanceState);
  31  setContentView(R.layout.activity_main);
  32  
  33  
  34  //startet Upgrade als Standard
  35  
  36  @SuppressLint("SetJavaScriptEnabled")
  37  
  38  
  39  WebView myWebView = (WebView) findViewById (R.id.webView1);
  40  myWebView.getSettings().setJavaScriptEnabled(true);
  41  myWebView.loadUrl("WEBSITE");
  42  myWebView.setWebViewClient(new WebViewClient());
  43  
  44  
  45  }
  46  
  47  
  48  
  49  /*public boolean onCreateOptionsMenu(Menu menu) {
  50  // Inflate the menu; this adds items to the action bar if it is present.
  51  getMenuInflater().inflate(R.menu.main, menu);
  52  return true;
  53  }
  54  */
  55
  56  
  57  public boolean shouldOverrideUrlLoading(WebView view, String url) {
  58  if (url.startsWith("mailto:")) {
  59  Intent intent = new Intent(Intent.ACTION_VIEW,
  60  Uri.parse(url));
  61  startActivity(intent);
  62  }else if(url.startsWith("http:") || url.startsWith("https:")) {
  63  view.loadUrl(url);
  64  }
  65  return true;
  66  }
  67  
  68  
  69  public void button1click (View view) {
  70  
  71  Code
  72  
  73  }
  74  
  75  
  76  public void button2click (View view) {
  77  
  78  Code
  79  
  80  }
  81
  82
  83  
  84  public void button3click (View view) {
  85  
  86  Code
  87  
  88  }
  89  
  90  
  91  
  92  public void button5click (View view) {
  93  
  94  Code
  95  
  96  }
  97
  98  
  99  
  100}
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>If I try this I get the error message "The method replaseFirst(String) is undefined for the type String". In cause of this I changed <code>url.replaseFirst</code>  to <code>url.replaceFirst</code> but his needs a secound argument so I have to write <code>url.replaceFirst("mailto:", X );</code>. For X I can type <code>mail</code>,<code>url</code> or <code>null</code>. I tryed everyone, by each I get the message that I have to add a return statement, so I did it with <code>return false</code>.
  Now I have this code:</p>
  
  <pre><code>public class MyWebViewClient extends WebViewClient {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  if(url.startsWith("mailto:")) {
                        String mail = url.replaceFirst ("mailto:", mail);
                        Intent intent = new Intent(Intent.ACTION_SEND);
                        intent.setType("message/rfc822");
                        intent.putExtra(Intent.EXTRA_EMAIL, mail );
  
  
                        startActivity(Intent.createChooser(intent, "Send Email"));
               }
                  return false;
          }
      }
  </code></pre>
  
  <p>This does not work. So I try <code>intent.setType("message/rfc822");</code> instead of <code>intent.setType("text/plain");</code>  but this also does not work.</p>
  
  <p>What I have done wrong?</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p><strong>new code:</strong></p>
  
  <pre><code>public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if(url.startsWith("mailto:")) {
                  String mail = url.replaceFirst("mailto:", "");
                  Intent intent = new Intent(Intent.ACTION_SEND);
                  intent.setType("text/plain");
                  intent.putExtra(Intent.EXTRA_EMAIL, mail );
  
                  startActivity(Intent.createChooser(intent, "Send Email"));
               }  
              else if(url.startsWith("http:") || url.startsWith("https:")) {
                      view.loadUrl(url);
                  }
                  return true;
          }
  </code></pre>