title: Android - How to run intent from JavaScript
body: <p>I am new to Android and Java. I have constructed an app using HTML/Javascript that is working great.</p>
  
  <p>I now need to create an activity that launches the email client, fills in subject and body, and (the tough part) adds a file attachment. I have not been able to do this from within JavaScript, <code>mailto:</code> will not attach the file.</p>
  
  <p>So I need to accomplish this through Java and execute it from JavaScript. I think this can be done by using <code>addJavaScriptInterface</code> but I cannot find any detailed documentation or examples to go off of.</p>
  
  <p>How could I do this?</p>
  
  <p>Here is what I have so far after reading the documentation:</p>
  
  <p>2nd update to code:</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends DroidGap {
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      super.setIntegerProperty( "splashscreen", R.drawable.splash );
      super.loadUrl("file:///android_asset/www/index.html", 1000);
      WebView mWebView;
      mWebView = (WebView)findViewById(R.id.webview);
      mWebView.getSettings().setJavaScriptEnabled(true);
      mWebView.addJavascriptInterface(new JavaScriptInterface(), "Android"); 
  }
  }
  </code></pre>
  
  <p>JavaScriptInterface.java</p>
  
  <pre><code>public class JavaScriptInterface {
  
  public void doEmail(){
      Intent sendIntent = new Intent(Intent.ACTION_SEND);
      sendIntent.setType("text/html");
      sendIntent.putExtra(android.content.Intent.EXTRA_TEXT,"test text");
      sendIntent.putExtra(Intent.EXTRA_SUBJECT,"test subject");
      sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
      sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://test co.html"));
      startActivity(Intent.createChooser(sendIntent, "Send email..."));
      } 
  }
  </code></pre>
  
  <p>Then I would reference the intent through JavaScript by using Android.doEmail().</p>
  
  <p>With the above code I am getting 2 errors in Eclipse
  1. The method startActivity(Intent) is undefined for the type - JavaScriptInterface
  2. webview cannot be resolved or is not a field - MainActivity</p>
  
  <p>What am I doing wrong?</p>